首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法远程连接到MariaDB服务器

问无法远程连接到MariaDB服务器
EN

Stack Overflow用户
提问于 2022-11-27 17:08:35
回答 1查看 26关注 0票数 0

我知道大家都在讨论这个问题,对你们中的一些人来说,这可能是一件很简单的事情,但作为一名n00b并试图自己解决这个问题让我抓狂。我有两个VPS运行的Ubuntu服务器20.04LTS。

VPS #1运行MariaDB服务器10.3.34。没有防火墙运行(没有iptable,没有ufw,什么都没有);

代码语言:javascript
复制
/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

在终端输出中执行netstat -ant _ grep 3306:

代码语言:javascript
复制
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添加了一个用户,授予远程访问的所有权限,一切看起来都很好!

代码语言:javascript
复制
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.04LTS,我还安装了mariadb客户端和telnet。

尝试: mariadb -u xxxuser -h SERVERIP -P 3306 -p

代码语言:javascript
复制
    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")

试图对产出进行电信:

代码语言:javascript
复制
telnet SERVERIP 3306
Trying SERVERIP...
telnet: Unable to connect to remote host: Connection timed out

请给我任何可能的帮助/支持。一切都会被感激的!谢谢!

EN

回答 1

Stack Overflow用户

发布于 2022-11-27 17:35:27

如果无法与root用户登录

执行下列步骤:

  1. Stop mariadb services

代码语言:javascript
复制
1. Run mysqld safe version by below command: `sudo mysqld_safe --skip-grant-tables` &
代码语言:javascript
复制
2. Run mysql client with below command on new terminal: `mysql -u root`
代码语言:javascript
复制
3. Set password in user table of mysql database:

use mysql;

update user SET PASSWORD=PASSWORD("<new_password>") WHERE USER='root';

flush privileges;

和出口

代码语言:javascript
复制
4. Login with new password, set in above command:

mysql -u root -p Enter password: <new_password>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74592091

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档