navcat 连接centos docker 下的mysql服务

docker下mysql的设置

	1:首先进入docker容器下mysql服务
	  docker ps 查看mysql服务的id
[root@docker-compose ~]# docker ps
	CONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS              PORTS                           NAMES
	e5071d1c78d1        mysql:5.6                        "docker-entrypoint..."   41 minutes ago      Up 41 minutes       192.168.78.199:3306->3306/tcp   root_mysql_1
	d530516788b8        redis                            "docker-entrypoint..."   17 hours ago        Up About an hour    6379/tcp                        root_redis_1
	b8f69802e1c9        devilbox/php-fpm:5.2-work-0.89   "/docker-entrypoin..."   24 hours ago        Up About an hour    9000/tcp                        root_php_1
	71ef37f34018        nginx:alpine                     "/docker-entrypoin..."   43 hours ago        Up About an hour    0.0.0.0:80->80/tcp              root_nginx_1
	2:我这里mysql id是 e5071d1c78d1 
	docker exec -it e5071d1c78d1  /bin/sh
	进入mysql容器中
# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.48 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> 
	创建用户以及给与navicat可以连接的权限,创建名为llh2025的用户以及密码为123456,
	然后给予所有权限getllh2025用户,最后刷新设置
	CREATE USER 'llh2025'@'%' IDENTIFIED BY '123456';
	grant all privileges on *.* to 'llh2025'@'%';
	grant SUPER on *.* to 'llh2025'@'%';
	flush privileges;
	环境为centos7 
	开启mysql服务的时候,指定端口前ip为本机ip就可以了,我这个是docker-compose.yml文件下的端口映射,:
	ports:
     - 192.168.78.199:3306:3306

验证结果

在这里插入图片描述
在这里插入图片描述

测试结束
(qq:九七二四三九三二九(972439329),有哪里出错欢迎指正,大家一起学习交流)

End

猜你喜欢

转载自blog.csdn.net/weixin_45005209/article/details/107382870