ubuntu 无法远程连接到MariaDB服务器

y0u0uwnf  于 2022-11-28  发布在  其他
关注(0)|答案(1)|浏览(376)

我知道这是讨论和讨论过,这可能是一个简单的事情对你们中的一些人,但作为一个n 00 b,并试图修复它自己让我疯狂.我有两个VPS的运行Ubuntu服务器20.04 LTS.
VPS #1运行MariaDB服务器10.3.34。没有防火墙运行(没有iptables,没有ufw,什么都没有);

/etc/mysql/mariadb.conf.d/50-server.cnf looks like this:

    
#
# * Basic Settings
#
user                    = mysql
pid-file                = /run/mysqld/mysqld.pid
socket                  = /run/mysqld/mysqld.sock
port                    = 3306
basedir                 = /usr
datadir                 = /var/lib/mysql
tmpdir                  = /tmp
lc-messages-dir         = /usr/share/mysql
#skip-external-locking

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

正在执行网络统计|终端输出中的grep 3306:

netstat -ant | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:3306          127.0.0.1:46154         TIME_WAIT
tcp        0      0 127.0.0.1:3306          127.0.0.1:59448         TIME_WAIT
tcp        0      0 127.0.0.1:3306          127.0.0.1:46174         TIME_WAIT
tcp        0      0 127.0.0.1:3306          127.0.0.1:46184         TIME_WAIT
tcp        0      0 127.0.0.1:3306          127.0.0.1:59432         TIME_WAIT
tcp        0      0 127.0.0.1:3306          127.0.0.1:59442         TIME_WAIT
tcp        0      0 127.0.0.1:46162         127.0.0.1:3306          TIME_WAIT

我确实向MariaDB添加了一个用户,授予远程访问的所有权限,一切似乎都很好!

MariaDB [(none)]> CREATE DATABASE xxxdb;
MariaDB [(none)]> CREATE USER  'xxxuser'@'%' IDENTIFIED BY 'password';
MariaDB [(none)]> GRANT ALL ON *.* to 'xxxuser'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

VPS#2运行Ubuntu服务器20.04 LTS,我也安装了mariadb客户端和telnet。
正在尝试:mariadb -u xxxuser -h服务器IP-P 3306 -p

mariadb -u xxxuser -h SERVERIP -P 3306 -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on 'SERVERIP' (110 "Connection timed out")

尝试telnet输出:

telnet SERVERIP 3306
Trying SERVERIP...
telnet: Unable to connect to remote host: Connection timed out

请给予我任何帮助/支持,你可以。任何将不胜感激!谢谢!

piah890a

piah890a1#

如果无法以root用户身份登录
执行以下步骤:
1.停止mariadb服务
1.通过以下命令运行mysqld安全版本:sudo mysqld_safe --skip-grant-tables
1.在新终端上使用以下命令运行mysql客户端:mysql -u root
1.在mysql数据库的用户表中设置密码:
use mysql;
update user SET PASSWORD=PASSWORD("<new_password>") WHERE USER='root';
flush privileges;
及退出了
1.使用上面命令中设置的新密码登录:
mysql -u root -p Enter password: <new_password>

相关问题