docker安装mysql5.7镜像和容器

1.下载镜像

[root@192 ~]# sudo docker pull mysql/mysql-server:5.7
5.7: Pulling from mysql/mysql-server
35defbf6c365: Pull complete 
0fa46ab0f51d: Pull complete 
f70f5000008c: Pull complete 
892ac46af8c0: Pull complete 
Digest: sha256:ddb046076781a15200d36cb01f8f541c3481bedebd5e92646d8c617ae212c
Status: Downloaded newer image for mysql/mysql-server:5.7

2.创建mysql5.7的容器

[root@192 ~]# sudo docker run --name mysql5.7 -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -d mysql/mysql-server:5.7
2b102c12fb6348b17790b5560b763c8d575649ec535aa4b713e5d559cf5a

3.进入mysql容器内

[root@192 ~]# docker exec -it mysql5.7 bash
bash-4.2#

4.登录mysql

bash-4.2# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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.

mysql>

5.修改mysql允许远程连接

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的mysql密码' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> FLUSH  PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

你可能感兴趣的:(docker安装mysql5.7镜像和容器)