//目前最新的为mysql8
sudo docker run -itd --restart unless-stopped --net=host --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -v /my/own/datadir:/var/lib/mysql mysql:8.0.1
mysql 官方docker 需要重新设置密码,否则无法远程连接 step 1 : docker exec -it [容器id] /bin/bash step 2 : 登陆mysql ==> mysql -uroot -h localhost -proot >use mysql; mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'newpassword'
mysql8.1 之后:
ALTER USER 'root'@'%' IDENTIFIED WITH caching_sha2_password BY '密码';
The default configuration for MySQL can be found in /etc/mysql/my.cnf
, which may !includedir
additional directories such as /etc/mysql/conf.d
or /etc/mysql/mysql.conf.d
. Please inspect the relevant files and directories within the mysql
image itself for more details.
目前位置 : /etc/my.cnf 可以添加 [mysqld] 'max_connections = 3000 ' 到 /etc/my.cnf 然后重启
# 查看最大连接数:
SHOW VARIABLES LIKE 'max_connections'; # 临时设置 SET GLOBAL max_connections = 2000;
--privileged=true
mysql 9
sudo docker run -itd --restart=unless-stopped --net=host --name sea-mysql9 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root \ -v /var/lib/docker/mysql9datadir:/var/lib/mysql \ mysql:9.4.0 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
可能出现的问题:
Plugin 'mysql_native_password' is not loaded
数据库从 mysql5.7 升级到 mysql8.4,部分场景出现以下错误提示: Plugin 'mysql_native_password' is not loaded 原因是:mysql_native_password 插件(模式)在新版本中被弃用了,新模式为 caching_sha2_password,需要启用一下旧模式。 解决步骤: 1.连接到数据库后,用命令 SHOW PLUGINS 查看插件列表 可以看到插件【mysql_native_password】的状态为【DISABLED】 我们的需要将其状态改为【ACTIVE】,修改步骤在后面。 2.找到配置文件 my.ini 进行修改 配置文件位置举例:C:\ProgramData\MySQL\MySQL Server 8.4\my.ini 在my.ini最后一行添加: mysql_native_password=ON 3.重启mysql服务,命令示例: net start mysql84 net stop mysql84 4.再次连接到数据库,用命令 SHOW PLUGINS 查看插件列表 可以看到插件【mysql_native_password】的状态为【ACTIVE】 5.为用户启用旧的身份验证插件【mysql_native_password】 ALTER USER '账号'@'主机' IDENTIFIED WITH 'mysql_native_password' BY '密码'; FLUSH PRIVILEGES; 举例: ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY 'root'; FLUSH PRIVILEGES; 此时,问题就解决了。
常用的mysql5.7:
sudo docker run -it -d --restart unless-stopped -p 13306:3306 -h mysql --name mysql -e MYSQL_ROOT_PASSWORD=root alanpeng/mysql5.7-replication-docker
sudo docker run -itd --restart unless-stopped -p 3306:3306 --net=host -h mysql --name mysql -e MYSQL_ROOT_PASSWORD=root alanpeng/mysql5.7-replication-docker
修改:
(如果不是在docker中 vi /etc/mysql/my.cnf)
vi /etc/mysql/mysql.conf.d/mysqld.cnf
cd /etc/mysql/mysql.conf.d
echo 'sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' >> mysqld.cnf
echo 'explicit_defaults_for_timestamp = 1' >> mysqld.cnf
echo 'max_allowed_packet= 500M
' >> mysqld.cnf
mysql -uroot -p000000
1)展示user表的结构
mysql>desc user;
2)查询user表
mysql>select User, Host, Password from user;
3)修改user表,把Host表内容修改为%
mysql>update user set host='%' where user='root' and host='localhost';
4)删除root用户的其他host
mysql>delete from user where User='root'and Host='hadoop001 ';
mysql>delete from user where User='root'and Host='127.0.0.1';
mysql>delete from user where User='root'and Host='::1';
6)刷新
mysql>flush privileges;