文章内容

2022/4/7 17:34:59,作 者: 黄兵

MySQL 升级到 8.0 无法远程连接

今天升级了一台腾讯云的 CVM 服务器,从原来的 16.04 升级到 20.04,具体升级过程可以查看这篇文章:After updating your package information, the essential package 'ubuntu-minimal' could not be located. This may be because you have no official mirrors listed in your software sources,升级完成之后无法连接 MySQL 数据库,原来版本是可以远程连接的,应该是在升级的过程中,将配置文件也给升级了。

我们通过登录 MySQL 数据库可以看到当前版本:

已经更新到 8.0.28,原来应该是 6.x 版本。

首先我们查看用户是否可以远程连接,执行下面 SQL 代码:

use mysql;
select host,user from user;

可以看到原来的用户是可以远程连接的:

我们需要排查配置文件是否改变,现在的配置文件路径是:/etc/mysql/mysql.conf.d,我们查看 mysqld.cnf 文件内容:

有如下重要内容:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address		= 127.0.0.1
mysqlx-bind-address	= 127.0.0.1

可以看出现在是绑定在本地地址,只用本地用户可以登录,远程用户无法登录。

我们注释掉上面的 bind-addressmysqlx-bind-address,就可以远程连接了。

关于 mysqlx-bind-address 的官方说明:X Plugin 侦听 TCP/IP 连接的网络地址。此变量不是动态的,只能在启动时配置。这是 bind_address 系统变量的 X Plugin 等价物。

之后重启 MySQL 服务:

sudo systemctl restart mysql

之后再次连接远程数据库,已经成功。


参考资料:

1、20.5.6.2 X Plugin Options and System Variables

2、MySQL数据库无法远程连接的解决办法


黄兵个人博客原创。

转载请注明出处:黄兵个人博客 - MySQL 升级到 8.0 无法远程连接

分享到:

发表评论

评论列表