重新搞 WEB 开发

2020-10-15  本文已影响0人  ssevening

通过:
https://www.jianshu.com/p/4fc53d7d7620
安装 mysql:

<article class="_2rhmJa">

一、安装

1、执行安装命令

brew install mysql

2、安装完后启动mysql

mysql.server start

3、执行安全设置

mysql_secure_installation

显示如下

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

按照提示选择密码等级,并设置root密码

二、创建新的数据库、用户并授权

1、登录mysql

mysql -u root -p

按提示输入root密码

root@poksi-test-2019:~# mysql -u root -p
Enter password: 

2、创建数据库

create database retail_db character set utf8mb4;

3、创建用户

create user 'retail_u'@'%' identified by 'retail_PWD_123';

4、授权用户

grant all privileges on retail_db.* to 'retail_u'@'%';

flush privileges;

5、查看当前的数据库

show databases;

6、显示当前数据库的表单

show tables

三、建表

CREATE TABLE t_user(
  key_id VARCHAR(255) NOT NULL PRIMARY KEY,  -- id 统一命名为key_id
  user_name VARCHAR(255) NOT NULL ,
  password VARCHAR(255) NOT NULL ,
  phone VARCHAR(255) NOT NULL,
  deleted INT NOT NULL DEFAULT 0,  -- 逻辑删除标志默认值
  create_time   timestamp NULL default CURRENT_TIMESTAMP, -- 创建时间默认值
  update_time   timestamp NULL default CURRENT_TIMESTAMP -- 修改时间默认值
) ENGINE=INNODB AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8mb4;

四、检查mysql服务状态

先退出mysql命令行,输入命令

systemctl status mysql.service

显示如下结果说明mysql服务是正常的

● mysql.service - MySQL Community Server
  Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
  Active: active (running) since Wed 2019-05-22 10:53:13 CST; 13min ago
Main PID: 16686 (mysqld)
   Tasks: 29 (limit: 4667)
  CGroup: /system.slice/mysql.service
          └─16686 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

May 22 10:53:12 poksi-test-2019 systemd[1]: Starting MySQL Community Server...
May 22 10:53:13 poksi-test-2019 systemd[1]: Started MySQL Community Server.

装完了mysql 后傻 X 了,不知道 root 的用户名和密码。
修改默认 Root 密码:
MySQL:ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

build.gradle中修改 version = '0.2.5' 后
直接开始启动
./gradlew build && java -jar build/libs/gs-spring-boot-docker-0.2.2.jar

打包成docker 镜像
docker build --build-arg JAR_FILE=build/libs/*.jar -t ssevening/gs-spring-boot-docker .

docker images; 查看所有镜像

添加好标签
docker tag 7615ad030a17 ssevening/gs-spring-boot-docker:0.2.5

删除 TAG
docker rmi ssevening/gs-spring-boot-docker:0.2.2

推送到docker 仓库:docker push ssevening/gs-spring-boot-docker

去阿里云服务器上 拉取镜像
docker pull ssevening/gs-spring-boot-docker

启动应用
docker run -p 80:8080 -t ssevening/gs-spring-boot-docker /bin/bash

终止容器,如果已经有一个容易在运行的话:
使用docker stop $CONTAINER_ID来终止一个运行中的容器。并且可以使用docker ps -a来看终止状态的容器。

阿里云启动后 安全退出
nohup docker run -p 80:8080 -t ssevening/gs-spring-boot-docker /bin/bash &

最后,一定要 exit

添加用户
CREATE USER 'superdeals'@'localhost' IDENTIFIED BY 'Hello1234';

mysql> CREATE USER 'superdeals'@'localhost' IDENTIFIED BY 'Hello1234';
mysql> GRANT ALL PRIVILEGES ON . TO 'superdeals'@'%' WITH GRANT OPTION;

打开所有IP 可以连接
update user set host = ’%’ where user = ’root’;

Docker中安装mysql
docker pull mysql:latest
查看镜像
docker images
4、运行容器 开启mysql
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=Hello1234 mysql
docker ps;
加容器名:
docker exec -t -i 7c4baed6803a /bin/bash

docker 中下载 mysql

docker pull mysql

启动

docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=Lzslov123! -d mysql

进入容器

docker exec -it mysql bash

登录mysql

mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Lzslov123!';

添加远程登录用户

CREATE USER 'liaozesong'@'%' IDENTIFIED WITH mysql_native_password BY 'Lzslov123!';
GRANT ALL PRIVILEGES ON . TO 'liaozesong'@'%';

上一篇下一篇

猜你喜欢

热点阅读