mariadb登陆异常_ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘XXX‘ (111)

【现象】
近期,同事来找帮忙,说一MySQL数据库账号不能登陆了,看了下报错如下:
[root@localhost ~]# mysql -uuser_name -pXXXXXXXXX -h192.168.0.111 -P3306
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘192.168.0.111’ (111)

经查看:root本地账号是可以登录的,如下:
[root@localhost ~]# /opt/lampp/bin/mysql -uroot -p’XXXXXXX’
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.4.11-MariaDB Source distribution

Copyright © 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]>

【排查思路】
1.该库非MySQL,而是MariaDB,此消息反馈给项目组核实,虽然两者的命令几乎都是共用,但毕竟背后的团队不是一家,看了下版本为:
MariaDB [(none)]> select @@version;
±----------------+
| @@version |
±----------------+
| 10.4.11-MariaDB |
±----------------+
1 row in set (0.000 sec)

通常此类问题有如下排查思路:
1.网络连接问题,通过ping和telnet命令很容易排除;
2.用户名和密码是否有误;
3.排查–port问题,没有指定–port,用的是3306,可能MySQL进程用的是其他端口

这里注意一个是知识点:
MySQL本地连接,如果不指mysql --protocol=tcp, 连接默认是socket方式;
MySQL socket连接是根据sokect文件来的,与–port不相关,如果是一机多个MySQL进程,则用-S(或者–socket=name )来指定连接哪个MySQL进程。

4.参数设置问题:在[mysqld]下设置skip_networking

如果设置了此参数为(为ON),使用MySQL只能通过本机Socket连接(socket连接也是本地连接的默认方式),放弃对TCP/IP的监听,当然也不让本地java程序连接MySQL(Connector/J只能通过TCP/IP来连接)。

5.参数设置问题:在[mysqld]下设置bind_address=127.0.0.1(当然也可以是其他ip)
如设置了此参数,可以TCP/IP连接,但也只能用绑定ip进行连接MySQL。

【问题解决】
经排查,上述排查思路1,2,3均无问题。
但4和5问题出现,即[mysqld]下设置skip_networking和bind_address均有设置,见下文标黄处。

[mysqld]
user=mysql
port=3306

bind-address=127.0.0.1
#Where do all the plugins live
plugin_dir=/opt/lampp/lib/mysql/plugin/

#Don’t listen on a TCP/IP port at all. This can be a security enhancement,
#if all processes that need to connect to mysqld run on the same host.
#All interaction with mysqld must be made via Unix sockets or named pipes.
#Note that using this option without enabling named pipes on Windows
#(via the “enable-named-pipe” option) will render mysqld useless!

#commented in by xampp security
skip-networking

注销掉,重启MySQL进程,使之参数生效,再次用文章开头命令连接MySQL,成功
[root@localhost ~]# mysql -uuser_name -pXXXXXXXXX -h192.168.0.111 -P3306
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.4.11-MariaDB Source distribution

Copyright © 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]>

【总结】
1.此类连通性问题,基本从文中5个方面排查,应该大部门遇到的问题都能解决;
2.没有玩过mariadb,但通过此次接触,基本感受不到MySQL和MariaDB有何区别,真的是兄弟俩,Oracle公司虽收购了MySQL,但早起的一些命令封装却是保留了下来,以至于MySQL原发团队后来另开发的MariaDB开源在命令层,保持了一致性或者说是兼容性;毕竟两者都是标榜的开源产品,彼此成就,也是一件美事。

欢迎关注个人微信公众号“一森咖记”图片
image.png

猜你喜欢

转载自blog.csdn.net/db_murphy/article/details/113177675
今日推荐