我已经花了一天的时间挠头,可能读了很多文章,以及如何允许我的MariaDB监听远程连接。不幸出现以下错误。
Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MariaDB server.
我还阅读了StackOverflow question,anotherQuestion,并能够成功创建新用户并通过以下MySQL查询授予所有权限。
CREATE USER 'ahsensaeed'@'%' IDENTIFIED BY 'my_password';
GRANT ALL PRIVILEGES ON *. TO 'ahsensaeed'@'%' WITH GRANT OPTION;
以下是我的被感动的用户资助。
MariaDB [mysql]> show grants for 'ahsensaeed'@'%';
+--------------------------------------------------------------------------------------------------------------------------------------+
| Grants for ahsensaeed@% |
+--------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'ahsensaeed'@'%' IDENTIFIED BY PASSWORD '*F794ABE2A12665587C6B6D8B61E2F7E987711AFA' WITH GRANT OPTION |
+--------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
最后,我只是清空特权,然后,转到我的MariaDB配置文件并对其进行编辑。下面是我的MariaDB conf文件放置的路径。
/etc/mysql/mariadb.conf.d/50-server.cnf
下面显示了我的MariaDB文件块。
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/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
.....
.....
,然后我通过/etc/init.d/mysql restart重新启动 mysql 服务。我还在客户端上为 mysql 打开3306端口。
当上述解决方案不起作用时,我还在/etc/mysql/conf.d/mysql.cnf文件中添加了 bind-address = 0.0.0.0 ,但仍然失败,并出现错误。
下面显示了我如何从服务器请求MariaDB数据库。
-> mysql -uahsensaeed -p -h hostIp
然后出现以下错误。
错误1130(HY000):不允许主机'hostIp'连接到此MariaDB服务器
编辑。添加了主机和用户数据。
MariaDB [(none)]> select User,Host from mysql.user;
+------------+-----------+
| User | Host |
+------------+-----------+
| ahsensaeed | % |
| root | localhost |
+------------+-----------+
2 rows in set (0.00 sec)
任何帮助将不胜感激。
答案 0 :(得分:0)
这对我有用(我使用Ubuntu 18.04作为虚拟机,而Windows 10使用Vagrant):
sudo mysql -e "CREATE DATABASE {db_name};"
sudo mysql -e "CREATE USER {user_name}@localhost IDENTIFIED BY '{password}';"
sudo mysql -e "UPDATE mysql.user SET Host='%' WHERE User='{user_name}';"
sudo mysql -e "GRANT ALL PRIVILEGES ON {db_name}.* TO '{user_name}'@'%';"
sudo mysql -e "FLUSH PRIVILEGES;"
sudo systemctl restart apache2
sudo systemctl restart mariadb
之后,您应该编辑文件:
/etc/mysql/mariadb.conf.d/50-server.cnf
并将 bind-address 属性设置为您的hostIP地址,或仅对此行进行注释。
最后,运行命令:
sudo systemctl restart apache2
sudo systemctl restart mariadb
我希望这能满足您的需求