当前位置:   article > 正文

Docker安装Mysql8 阿里云Centos7 解决caching_sha2_password_阿里云rds 修改caching_sha2_password

阿里云rds 修改caching_sha2_password

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

镜像搜索下载查看

docker search mysql 
docker pull mysql:latest
--换镜像源之后好快
docker images
  • 1
  • 2
  • 3
  • 4

这里修改之前的命令
不要用 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

在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)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

完成
发现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)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

好了 可以远程登录了

最后 开机自启动
docker update mysql --restart=always

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/307940
推荐阅读
相关标签
  

闽ICP备14008679号