拉取挂载运行
指定版本:
docker run --restart=always --name mysql-server -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d openshift/mysql-55-centos7
最新版本:
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进行相关配置
docker exec -it <ID> /bin/bash
mysql -uroot -p初始密码
默认密码:root
设置访问权限
use mysql
update user set host='%' where user='root';
select user,host from user;
设置密码
默认规则:包含大小写数字与特殊字符,不小于8位
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';31404e2ec8 ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
alter user 'root'@'%' identified with mysql_native_password BY '新密码'; alter user 'root'@'%' identified with mysql_native_password BY 'root';
更新配置
flush privileges;
更新容器源
apt-get update
下载编辑器
apt-get install vim
修改字符编码
vi /etc/my.cnf vi /etc/mysql/my.cnf
[mysqld]上添加
[client]
default-character-set=utf8
[mysqld]最下面添加
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
[mysql]
default-character-set=utf8
重启登录查看
show variables like 'character%';
select now();
查看时区
show VARIABLES like '%time_zone%';
仅修改当前会话的时区,停止会话失效
set time_zone = '+8:00';
修改全局的时区配置
set global time_zone = '+8:00';
flush privileges;
连接测试
mysql5.7以后分组报错解决
[mysqld]下加入重启,注意格式
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
未开启远程操作权限
win+R->cmd进入登录自己的mysql:
输入命令:mysql -u root -p ****(输入自己的密码)
输入远程命令:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '31404e2ec8' WITH GRANT OPTION;(输入自己的用户名和密码)
刷新:flush privileges;
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