赞
踩
Docker安装Mysql8
阿里云自己的镜像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://换成自己的.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
镜像搜索下载查看
docker search mysql
docker pull mysql:latest
--换镜像源之后好快
docker images
这里修改之前的命令
不要用 rm 参数 停掉容器后就自己删了
换成下面的这个 密码用root吧 记不住
docker run -p 3306:3306 --name mysql8
-v /usr/mysql/conf:/etc/mysql
-v /usr/mysql/log:/var/log/mysql
-v /usr/mysql/data:/var/lib/mysql
-e MYSQL_ROOT_PASSWORD=root
-d mysql
在mysql8的时候 只要有挂在路径 我这就没法启动,目前是不挂载目录启动
启动安装 进入设置用户
create database testdb character set utf8;
grant all privileges on testdb.* to ‘yognhu’@’%’;
flush privileges;
docker run -it --rm --name mysql -e MYSQL_ROOT_PASSWORD=密码 -p 3306:3306 -d mysql 进入 docker exec -it mysql bash root@4091662cc52f:/# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.21 MySQL Community Server - GPL 这里发现最新的是8.0.21版本 Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 创建用户dev 数据库blog 授权 远程登录 mysql> create user dev identified by '密码'; Query OK, 0 rows affected (0.02 sec) mysql> create database blog character set utf8 -> ; Query OK, 1 row affected, 1 warning (0.00 sec) mysql> grant all privileges on blog.* to 'dev'@'%'; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges -> ; Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges ON blog.* TO 'dev'@'%'; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges -> ; Query OK, 0 rows affected (0.00 sec) mysql> SHOW GRANTS FOR dev; +-----------------------------------------------+ | Grants for dev@% | +-----------------------------------------------+ | GRANT USAGE ON *.* TO `dev`@`%` | | GRANT ALL PRIVILEGES ON `blog`.* TO `dev`@`%` | +-----------------------------------------------+ 2 rows in set (0.00 sec)
完成
发现dev用户远程登不进去
Authentication plugin ‘caching_sha2_password’ cannot be loaded
权限还有问题 再授权刷新一遍
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.01 sec) mysql> mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码'; Query OK, 0 rows affected (0.00 sec) mysql> mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> ALTER USER 'dev'@'%' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.01 sec) mysql> ALTER USER 'dev'@'%' IDENTIFIED WITH mysql_native_password BY '密码'; Query OK, 0 rows affected (0.01 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
好了 可以远程登录了
最后 开机自启动
docker update mysql --restart=always
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。