蓝色的天_90  

继上一篇安装mysql 后外部访问mysql 时会有日下错误提示

 

 下面就来解决一下

1,登进MySQL,使用如下命令

mysql -uroot -p

#输入密码
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
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>

 

2,输入以下语句,进入mysql库:

use mysql;

3,更新域属性,'%'表示允许外部访问:

mysql> update user set host='%' where user ='root';
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

4,执行以上语句之后再执行:

FLUSH PRIVILEGES;  #刷新权限

5,再执行授权语句:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
Query OK, 0 rows affected (0.02 sec)

然后外部就可以通过账户密码访问了。

 

 

 

6,其它说明:

FLUSH PRIVILEGES; 命令本质上的作用是:

将当前user和privilige表中的用户信息/权限设置从mysql库(MySQL数据库的内置库)中提取到内存里。

MySQL用户数据和权限有修改后,希望在"不重启MySQL服务"的情况下直接生效,那么就需要执行这个命令。

通常是在修改ROOT帐号的设置后,怕重启后无法再登录进来,那么直接flush之后就可以看权限设置是否生效。

而不必冒太大风险。

 

三、可能存在的其它问题:

执行完之后,再用Navicat连接mysql,报错如下:

Client does not support authentication protocol requested by server;

 

报错原因:

mysql8.0 引入了新特性 caching_sha2_password;这种密码加密方式Navicat 12以下客户端不支持;

Navicat 12以下客户端支持的是mysql_native_password 这种加密方式;

解决方案:

1,用如下语句查看MySQL当前加密方式

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)

看第一行,root加密方式为caching_sha2_password。

2,使用命令将他修改成mysql_native_password加密模式:

update user set plugin='mysql_native_password' where user='root';

再次连接的时候,就成功了。

四、如果还连接不上

通过以上操作后,依然无法连接上,问题可能出在了防火墙上。

1,MySQL部署在实体服务器上解决方案如下:
a.开放MySQL的端口号,默认端口号是3306。

参照防火墙命令7、8
b.直接关闭防火墙(慎重操作,不建议。)

参照防火墙知识 2、3

五、防火墙相关知识

Centos7默认安装了firewalld,如果没有安装的话,可以使用

 yum install firewalld firewalld-config

进行安装。

1:查看防火状态

systemctl status firewalld

service  iptables status

 

2:暂时关闭防火墙

systemctl stop firewalld

service  iptables stop

 

3:永久关闭防火墙

systemctl disable firewalld

chkconfig iptables off

4:打开防火墙

systemctl enable firewalld

service iptables restart  

5、将接口添加到区域(默认接口都在public)

firewall-cmd --zone=public --add-interface=eth0(永久生效再加上 --permanent 然后reload防火墙)

6、查看指定区域所有打开的端口

firewall-cmd --zone=public --list-ports

7、在指定区域打开端口(记得重启防火墙)

firewall-cmd --zone=public --add-port=8080/tcp(永久生效再加上 --permanent)

说明:

–zone 作用域
–add-port=8080/tcp 添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效

8、重启防火墙

firewall-cmd --reload

 

posted on 2020-04-30 09:13  蓝色的天_90  阅读(6301)  评论(0编辑  收藏  举报