linux 开放mysql端口

作者 : admin 本文共1700个字,预计阅读时间需要5分钟 发布时间: 2024-06-10 共4人阅读

问题

在配置mysql后,需要放开3306端口,出现了FirewallD is not running错误

[root@hadoop102 mysql]# firewall-cmd –zone=public –add-port=3306/tcp –permanent
FirewallD is not running

1.启动firewalld

systemctl start firewalld

2.查看firewalld

systemctl status firewalld
linux 开放mysql端口插图

3.重新开放端口

firewall-cmd –zone=public –add-port=3306/tcp –permanent

4.查看已开启的端口

firewall-cmd –list-ports

linux 开放mysql端口插图(1)

报错

开放之后,telnet连接还是提示

FHost ‘192.168.190.1‘ is not allowed to connect to this MySQL server

解释:

这个错误表示客户端尝试连接到MySQL服务器时,服务器检查到客户端的IP地址没有被授权访问权限。MySQL的用户权限是基于用户名和来源IP的组合来判断的。

解决办法:

1.在MySQL所在服务器上使用命令登录到MySQL数据库中

   mysql -u root -p

2.选择mysql数据库,并查询权限



3.查看权限

select host from user where user=’root’;

linux 开放mysql端口插图(2)

4.修改 (前后)

update user set host = ‘%’ where user =’root’;

linux 开放mysql端口插图(3)

5.刷新

flush privileges;

二.发现还是出现问题 (切记在切换验证插件的时候,重新修改一下密码)

linux 开放mysql端口插图(4)

 错误原因是加密方式的问题

    MySql 8.0.11 换了新的身份验证插件(caching_sha2_password),

    而原来的身份验证插件为(mysql_native_password)。

只需要更改一下加密方式即可解决

首先执行如下SQL语句进入mysql数据库

mysql>use mysql;

执行如下SQL语句查看加密方式

mysql>select user, plugin from user where user= ‘root’;

linux 开放mysql端口插图(5)

看到加密方式为caching_sha2_password。

执行如下SQL语句更改加密方式

mysql>alter user “root”@”%”  identified with mysql_native_password by “(your password)”;

把(your password)替换成你的密码

再次执行

mysql>select user, plugin from user where user= ‘root’;

看到加密方式已经改变

linux 开放mysql端口插图(6)

三.心态崩了,继续干。

linux 开放mysql端口插图(7)1045-Access denied for user root@192.168.194.1(using password:YES)解决方案

(切记在切换验证插件的时候,重新修改一下密码)刚才因为退出mysql没有修改密码,导致密码错误

3.1) 跳过MySQL密码验证

vi /etc/my.cnf

在第一行加入   skip-grant-tables

linux 开放mysql端口插图(8)

3.2)若MySQL已经启动,重启MySQL服务器

systemctl restart mysqld

3.3)将登录密码设置为空,然后退出 exit

update user set authentication_string=” where user=’root’;

3.4) 1.重新登录,2.刷新权限,3.重置密码

    1.mysql -uroot -p  两次回车

    2. flush privileges;

    3. ALTER USER ‘root’@’%’ IDENTIFIED BY ‘新密码’;

3.5)将跳过权限去掉

vi /etc/my.cnf

在第一行加入   skip-grant-tables  注释掉

linux 开放mysql端口插图(9)

成功连接

参考地址:ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password YES/NO)_error 1045 (28000): access denied for user ‘root’@-CSDN博客

本站无任何商业行为
个人在线分享 » linux 开放mysql端口
E-->