After the docker container mounting successful, if you need to install mysql image, then:
- Search
mysql
the mirror, you can go in the browserdocker hub
's official website search mysql corresponding mirror and tag
[root@localhost sysconfig]# docker search mysql
- Select the appropriate version number, use the
docker pull mysql
command to install, if you want to specify a version directly plus a version number, if not, the default install the latest version behind the latest.
[root@localhost sysconfig]# docker pull mysql
- After the installation is complete, view the
docker
imagedocker images
, the command lists all the mirrors docker container, including just installedmysql
[root@localhost sysconfig]# docker images
- Start
mysql
:
#启动命令: docker run --name 自己起的名字 -e MYSQL_ROOT_PASSWORD='密码' -p 本机端口:容器端口 -d mysql
#其中: -e 指定mysql启动的密码参数,可以参照官网。
--name 指定一个启动的名字
-p 端口映射,如果不映射,则虚拟机外部访问不到该端口
-d 后台运行
[root@localhost sysconfig]# docker run --name mysql01 -e MYSQL_ROOT_PASSWORD='123456' -p 3306:3303 -d mysql
After starting the client will show the start of the container mirroring id, description start mysql
successfully.
5. Use navicat connection just started mysql
, reported error 2059, the error is as follows:
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password'
cannot be loaded: ÕÒ²»µ½Ö¸¶¨µÄÄ£¿é¡£
Solution:
- Enter the mysql command line:
#
[root@localhost sysconfig]# docker exec -it mysql01 /bin/bash
- Enter mysql -u root -p log
# 输入 mysql -u root -p 进行登录
root@5368bf2b1025:/# mysql -u root -p
Enter password:
# 登录成功后出现如下
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13 MySQL Community Server - GPL
Copyright (c) 2000, 2018, 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.
- Use the following command to change the encryption password.
# 使用一下命令修改密码的加密方式。
mysql> alter user 'root'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.07 sec)
- Re-connection.