Docker部署mysql远程连接解决2003的问题
连接MySQL
这⾥我使⽤navicat远程连接,连接MySQL前需要防⽕墙开放端⼝或者关闭防⽕墙。
开放端⼝
firewall-cmd --add-port=3306/tcp --permanent
// --permanent 永久⽣效,没有此参数重启后失效
firewall-cmd --reload
// 重新载⼊
关闭防⽕墙
systemctl stop firewalld
systemctl enable iptables
/
/ 设置开机启动
firewall-cmd --reload
// 重新载⼊
firewalld的基本使⽤
启动:systemctl start firewalld
关闭:systemctl stop firewalld
查看状态:systemctl status firewalld
开机禁⽤:systemctl disable firewalld
开机启⽤:systemctl enable firewalld
systemctl是CentOS7的服务管理⼯具中主要的⼯具,它融合之前service和chkconfig的功能于⼀体。
启动⼀个服务:systemctl start firewalld.service
关闭⼀个服务:systemctl stop firewalld.service
重启⼀个服务:systemctl restart firewalld.service
显⽰⼀个服务的状态:systemctl status firewalld.service
在开机时启⽤⼀个服务:systemctl enable firewalld.service
在开机时禁⽤⼀个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed
配置firewalld-cmd
查看版本:firewall-cmd --version
查看帮助:firewall-cmd --help
显⽰状态:firewall-cmd --state
查看所有打开的端⼝:firewall-cmd --zone=public --list-ports
更新防⽕墙规则:firewall-cmd --reload
查看区域信息:firewall-cmd --get-active-zones
查看指定接⼝所属区域:firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态:firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic
补充:Docker部署mysql远程连接解决1251
原因:
mysql 8.0 默认使⽤ caching_sha2_password ⾝份验证机制,客户端不⽀持新的加密⽅式。
解决⽅案:
docker进入容器修改⽤户(root)的加密⽅式
步骤:
1. 进⼊mysql容器内部
[root@localhost ~]# docker exec -it javakfmysql bash ## javakfmysql是容器的别名,这⾥也可以⽤容器的id代替
2. 登录mysql
root@e285125c99d6:/# mysql -u root -p
3. 设置⽤户配置项
查看⽤户信息
mysql> select host,user,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host | user | plugin | authentication_string |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| % | root | caching_sha2_password | $A$005$HF7;krfwhkKHp5fPenQm4J2dm/RJtbbyjtCUVdDCcboXQw3ALxsif/sS1 |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | localhost | mysql.session | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root | mysql_native_password | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
备注:host为 % 表⽰不限制ip localhost表⽰本机使⽤ plugin⾮mysql_native_password
修改加密⽅式
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; ### 123456 mysql的登录密码
flush privileges;
然后再查看⽤户信息
mysql> select host,user,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host | user | plugin | authentication_string |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| % | root | mysql_native_password | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | localhost | mysql.session | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root | mysql_native_password | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.00 sec)
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。如有错误或未考虑完全的地⽅,望不吝赐教。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论