//目前最新的为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
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'
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.
常用的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;