Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用MySQL工作台访问Mariadb(Centos 7)_Mysql_Mysql Workbench_Mariadb_Centos7 - Fatal编程技术网

无法使用MySQL工作台访问Mariadb(Centos 7)

无法使用MySQL工作台访问Mariadb(Centos 7),mysql,mysql-workbench,mariadb,centos7,Mysql,Mysql Workbench,Mariadb,Centos7,我已经在Centos 7上安装了Mariadb,我正在尝试使用MYSQL Workbench访问它 我已经做了以下工作: 启动并执行以下命令: systemctl start mariadb.service systemctl enable mariadb.service /usr/bin/mysql_secure_installation Autostart执行以下命令: systemctl start mariadb.service systemctl enable ma

我已经在
Centos 7
上安装了
Mariadb
,我正在尝试使用
MYSQL Workbench
访问它

我已经做了以下工作:

启动并执行以下命令:

 systemctl start mariadb.service
 systemctl enable mariadb.service
  /usr/bin/mysql_secure_installation
Autostart执行以下命令:

 systemctl start mariadb.service
 systemctl enable mariadb.service
  /usr/bin/mysql_secure_installation
启动MariaDB后(仅执行一次),执行以下命令:

 systemctl start mariadb.service
 systemctl enable mariadb.service
  /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 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_地址3306后。我无法通过其他VM或Windows访问。禁用防火墙后,它工作正常


@Alex我之前也检查过端口,它正在正确监听。感谢您的输入。

我从另一个类似的问题()中了解到,无法连接到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

检查如果您没有试图从远程连接访问mysqld服务器,则不应在防火墙中打开端口。localhost(127.0.0.1)不需要在3306上打开防火墙端口来访问mysql。如果您打开防火墙上的端口,您将允许远程访问mysql服务器。如果你不需要允许,那就太糟糕了。