无法使用 MySQL Workbench 访问 Mariadb (Centos 7)
Unable to access Mariadb (Centos 7) with MySQL Workbench
我已经在 Centos 7
上安装了 Mariadb
,我正在尝试使用 MYSQL Workbench
访问它。
我做了以下事情:
启动MariaDB执行以下命令:
systemctl start mariadb.service
自动启动MariaDB执行以下命令:
systemctl enable mariadb.service
启动 MariaDB 后(只执行一次),执行以下命令:
/usr/bin/mysql_secure_installation
当运行这个我去掉了匿名用户登录
我们还需要更改端口:
/etc/my.cnf.d/server.cnf
# Mariadb 网络设置
[mysqld]
# comment out the bind address
#bind_address=127.0.0.1
现在我会得到一个错误
[root@localhost ~]# mysql -u root -p mcellblock -h 192.168.159.163 -P 3306
Enter password:
ERROR 1130 (HY000): Host '192.168.159.163' is not allowed to connect to this MariaDB server
然后我启用了连接权限:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'mcb'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
MariaDB [mcellblock]> select User, Host, password from mysql.user where Host <> 'localhost';
+------+-----------------------+-------------------------------------------+
| User | Host | password |
+------+-----------------------+-------------------------------------------+
| root | localhost.localdomain | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | ::1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | % | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| mcb | % | *A071D903A1ABA9752B05C16C573A095C80A7AFAD |
+------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)
现在,当我尝试通过终端访问时,它起作用了:
$ mysql -u mcb -p mcellblock -h 192.168.159.163 -P 3306
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 28
Server version: 5.5.47-MariaDB MariaDB Server
但是当我尝试通过 MySQL Workbench 访问时出现错误:
Please check
1) Check that mysql is running on server 192.168.159.163 ** IT IS
2) Check that mysql is running on port 3306 ** I can connect to it via the terminal so I assume it is
3) Check mcb has the rights to connect to 192.168.159.163 from your address ** It should as its setup for %
4) Make sure you are both providing a password if needed and using the correct password for 192.168.159.163 ** the passwords are the same
当我在本地安装 MySQL Workbench 时,它可以工作,但不能远程安装。
有谁知道我遗漏了什么或如何解决这个问题?
如果你说的都是正确的,那么看起来更像是网络问题,所以,请执行:
netstat -punta | grep LISTEN
查找 mariadb 使用的端口并检查它是否类似于:
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 18137/mysqld
这里真正重要的是第 3 列,如果您看到它,则可能会少一个问题,如果没有,这意味着,基本上,您的 mysql 服务器正在本地侦听。
继续网络问题,也可能是防火墙阻止了您的连接,因此请确保一切正常。
原来是centos机器的防火墙问题。在使用 telnet IP_ADDRESS 3306 检查后。我无法通过我的其他 VM 或 Windows 进行访问。禁用防火墙后它起作用了。
@Alex 我之前也检查过端口并且它正在正确监听。感谢您的意见。
我从另一个类似的问题 (https://serverfault.com/questions/240015/how-do-i-allow-mysql-connections-through-selinux) 了解到,无法连接到 mysql 也可能是由于 SELinux。如果您不必从远程连接访问 mysqld,则不应在防火墙上打开端口。 SEL中允许访问MySQL的命令是:
检查 SELinux
sestatus
查看在 mysql 个进程上设置了哪些标志
getsebool -a | grep mysql
允许 Apache 通过 SELinux 连接到远程数据库
setsebool selinuxuser_mysql_connect_enabled 1
使用 -P 选项使更改永久生效。如果没有此选项,布尔值将在重新启动时重置为 0。
setsebool -P selinuxuser_mysql_connect_enabled 1
我已经在 Centos 7
上安装了 Mariadb
,我正在尝试使用 MYSQL Workbench
访问它。
我做了以下事情:
启动MariaDB执行以下命令:
systemctl start mariadb.service
自动启动MariaDB执行以下命令:
systemctl enable mariadb.service
启动 MariaDB 后(只执行一次),执行以下命令:
/usr/bin/mysql_secure_installation
当运行这个我去掉了匿名用户登录
我们还需要更改端口: /etc/my.cnf.d/server.cnf # Mariadb 网络设置
[mysqld]
# comment out the bind address
#bind_address=127.0.0.1
现在我会得到一个错误
[root@localhost ~]# mysql -u root -p mcellblock -h 192.168.159.163 -P 3306
Enter password:
ERROR 1130 (HY000): Host '192.168.159.163' is not allowed to connect to this MariaDB server
然后我启用了连接权限:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'mcb'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
MariaDB [mcellblock]> select User, Host, password from mysql.user where Host <> 'localhost';
+------+-----------------------+-------------------------------------------+
| User | Host | password |
+------+-----------------------+-------------------------------------------+
| root | localhost.localdomain | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | ::1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | % | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| mcb | % | *A071D903A1ABA9752B05C16C573A095C80A7AFAD |
+------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)
现在,当我尝试通过终端访问时,它起作用了:
$ mysql -u mcb -p mcellblock -h 192.168.159.163 -P 3306
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 28
Server version: 5.5.47-MariaDB MariaDB Server
但是当我尝试通过 MySQL Workbench 访问时出现错误:
Please check
1) Check that mysql is running on server 192.168.159.163 ** IT IS
2) Check that mysql is running on port 3306 ** I can connect to it via the terminal so I assume it is
3) Check mcb has the rights to connect to 192.168.159.163 from your address ** It should as its setup for %
4) Make sure you are both providing a password if needed and using the correct password for 192.168.159.163 ** the passwords are the same
当我在本地安装 MySQL Workbench 时,它可以工作,但不能远程安装。
有谁知道我遗漏了什么或如何解决这个问题?
如果你说的都是正确的,那么看起来更像是网络问题,所以,请执行:
netstat -punta | grep LISTEN
查找 mariadb 使用的端口并检查它是否类似于:
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 18137/mysqld
这里真正重要的是第 3 列,如果您看到它,则可能会少一个问题,如果没有,这意味着,基本上,您的 mysql 服务器正在本地侦听。
继续网络问题,也可能是防火墙阻止了您的连接,因此请确保一切正常。
原来是centos机器的防火墙问题。在使用 telnet IP_ADDRESS 3306 检查后。我无法通过我的其他 VM 或 Windows 进行访问。禁用防火墙后它起作用了。
@Alex 我之前也检查过端口并且它正在正确监听。感谢您的意见。
我从另一个类似的问题 (https://serverfault.com/questions/240015/how-do-i-allow-mysql-connections-through-selinux) 了解到,无法连接到 mysql 也可能是由于 SELinux。如果您不必从远程连接访问 mysqld,则不应在防火墙上打开端口。 SEL中允许访问MySQL的命令是:
检查 SELinux
sestatus
查看在 mysql 个进程上设置了哪些标志
getsebool -a | grep mysql
允许 Apache 通过 SELinux 连接到远程数据库
setsebool selinuxuser_mysql_connect_enabled 1
使用 -P 选项使更改永久生效。如果没有此选项,布尔值将在重新启动时重置为 0。
setsebool -P selinuxuser_mysql_connect_enabled 1