拉取挂载运行

指定版本:

  1. docker run --restart=always --name mysql-server -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d openshift/mysql-55-centos7

最新版本:

  1. docker run --name mysql-latest -p 3307:3306 -e MYSQL_ROOT_PASSWORD=root -v /root/mysql/conf.d:/etc/mysql/conf.d -v /rodata:/var/lib/mysql -d mysql:latest

登录mysql进行相关配置

  1. docker exec -it <ID> /bin/bash
  2. mysql -uroot -p初始密码

默认密码:root

设置访问权限

  1. use mysql
  2. update user set host='%' where user='root';
  3. select user,host from user;

设置密码

默认规则:包含大小写数字与特殊字符,不小于8位

  1. ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';31404e2ec8 ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
  2. alter user 'root'@'%' identified with mysql_native_password BY '新密码'; alter user 'root'@'%' identified with mysql_native_password BY 'root';

更新配置

  1. flush privileges;

更新容器源

  1. apt-get update

下载编辑器

  1. apt-get install vim

修改字符编码

  1. vi /etc/my.cnf vi /etc/mysql/my.cnf
  2. [mysqld]上添加
  3. [client]
  4. default-character-set=utf8
  5. [mysqld]最下面添加
  6. default-storage-engine=INNODB
  7. character-set-server=utf8
  8. collation-server=utf8_general_ci
  9. [mysql]
  10. default-character-set=utf8

重启登录查看

  1. show variables like 'character%';
  2. select now();

查看时区

  1. show VARIABLES like '%time_zone%';

仅修改当前会话的时区,停止会话失效

  1. set time_zone = '+8:00';

修改全局的时区配置

  1. set global time_zone = '+8:00';
  2. flush privileges;

连接测试

image.png

mysql5.7以后分组报错解决

[mysqld]下加入重启,注意格式

  1. sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

未开启远程操作权限

  1. win+R->cmd进入登录自己的mysql
  2. 输入命令:mysql -u root -p ****(输入自己的密码)
  3. 输入远程命令:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '31404e2ec8' WITH GRANT OPTION;(输入自己的用户名和密码)
  4. 刷新:flush privileges;
  1. grant all privileges on DB.* to 'root'@'47.103.19.123' identified by '31404e2ec8' with grant option;

MySQL8.0登录提示caching_sha2_password问题解决方法 https://blog.csdn.net/maoxinwen1/article/details/88629313