docker 安装mysql8无法远程登录
# 启动容器
docker run \
-p 13306:3306 \
--name mysql \
--privileged=true \
--restart=always \
-v /home/mysqldata/mysql:/etc/mysql \
-v /home/mysqldata/mysql/logs:/logs \
-v /home/mysqldata/mysql/data:/var/lib/mysql \
-v /etc/localtime:/etc/localtime \
-e MYSQL_ROOT_PASSWORD=cqrecadmin \
-d mysql:8.0.20
修改mysql字符集,
show variables like ‘%char%’
在挂载后的配置文件中打开/home/mysqldata/mysql/my.cnf,在[mysqld]后添加character-set-server=utf8
select host,user ,plugin from mysql.user;
更新root用户的密码加密方式为旧版本的native,以防一些客户端不兼容。
更新或者添加用户参考下面的语句;
1.添加用户
CREATE USER ‘zuoyueer’ IDENTIFIED BY ‘1223456’;
2.赋予权限
GRANT ALL PRIVILEGES ON . TO ‘zuoyueer’@‘%’;
3.修改加密规则
ALTER USER ‘zuoyueer’@‘%’ IDENTIFIED BY ‘1223456’ PASSWORD EXPIRE NEVER;
4.更新一下用户密码
ALTER USER ‘zuoyueer’@‘%’ IDENTIFIED WITH mysql_native_password BY ‘1223456’;
5.更新配置信息
FLUSH PRIVILEGES;