我是靠谱客的博主 开放外套,最近开发中收集的这篇文章主要介绍docker之mysql镜像以及外部navicat连接,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1. 拉取mysql镜像

docker pull mysql

2. 创建mysql容器

docker run --name=mysql -it -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql

–name之后定义名字,MYSQL_ROOT_PASSWORD为自己定义的密码

3. 查看所有容器

docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
88bbcb92959f        mysql               "docker-entrypoint.s…"   17 minutes ago      Up 17 minutes       0.0.0.0:3306->3306/tcp, 33060/tcp   mysql

4. 进入mysql容器

docker exec -it mysql bash

5. 安装vim和vi命令

apt-get update
apt-get install vim

6. mysql命令

root@88bbcb92959f:/# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 9
Server version: 8.0.20 MySQL Community Server - GPL

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.

mysql> 

7. Navicat 远程连接docker容器中的mysql

--查看 mysql的版本
mysql> status;
--------------
mysql  Ver 8.0.20 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:		12
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.0.20 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	latin1
Conn.  characterset:	latin1
UNIX socket:		/var/run/mysqld/mysqld.sock
Binary data as:		Hexadecimal
Uptime:			30 min 40 sec

Threads: 2  Questions: 8  Slow queries: 0  Opens: 133  Flush tables: 3  Open tables: 54  Queries per second avg: 0.004
--------------


8. 进行授权连接

mysql> GRANT ALL ON *.* TO 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;

9. 更改加密规则

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; 
Query OK, 0 rows affected (0.01 sec)

10. 更新root用户密码

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit;
Bye

最后

以上就是开放外套为你收集整理的docker之mysql镜像以及外部navicat连接的全部内容,希望文章能够帮你解决docker之mysql镜像以及外部navicat连接所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(28)

评论列表共有 0 条评论

立即
投稿
返回
顶部