我已经经历了很多教程和问题,但我仍然无法让它工作。
我去过:
我在 Ubuntu 16.04 上安装了 MariaDB。然后设置两个用户,其中一个是供公众使用的,所以我可以在这里发布。
用户添加为:
CREATE USER 'anon'@'%' IDENTIFIED BY '';
Run Code Online (Sandbox Code Playgroud)
本地连接是否有效?
是的,我可以通过服务器上的 ssh 以用户身份连接:
mysql -u anon
Run Code Online (Sandbox Code Playgroud)
您是否确认已正确添加用户?
我想是这样:
MariaDB [(none)]> SELECT User, Host FROM mysql.user WHERE Host <> 'localhost';
+------+------+
| User | Host |
+------+------+
| anon | % |
| user | % |
+------+------+
2 rows in set (0.01 sec)
Run Code Online (Sandbox Code Playgroud)
你打开防火墙了吗?
可能需要解除对防火墙的阻止:
[user]@popfreq:/etc/mysql$ firewall-cmd --add-port=3306/tcp
The program 'firewall-cmd' is currently not installed. You can install it by typing:
sudo apt install firewalld
Run Code Online (Sandbox Code Playgroud)
没有安装防火墙。
您是否检查了 my.cnf 文件的正确设置?
my.cnf
( [user]@popfreq:/etc/mysql
) 中的错误设置会导致它拒绝连接。这些是skip-networking
和bind-address
。我的文件看起来像这样:
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
Run Code Online (Sandbox Code Playgroud)
它根本没有违规行。
你检查其他配置文件了吗?
是的。他们也没有违规的台词。
telnet 能用吗?
不。
mint@mint-VirtualBox ~ $ telnet 128.199.203.208 3306
Trying 128.199.203.208...
telnet: Unable to connect to remote host: Connection refused
Run Code Online (Sandbox Code Playgroud)
不确定这意味着什么或如何解决。
服务器使用什么接口?
似乎只有本地:
[user]@popfreq:/etc/mysql/mariadb.conf.d$ sudo netstat -ntlup | grep mysql
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 16884/mysqld
Run Code Online (Sandbox Code Playgroud)
你记得重新启动吗?是的。我在所有尝试之间重新开始使用它:
sudo service mysql restart
Run Code Online (Sandbox Code Playgroud)
在我的情况下,错误的解决方案[mysqld]
是my.cnf
配置文件中根本没有任何部分。添加这个解决了这个问题:
[mysqld]
bind-address = ::
Run Code Online (Sandbox Code Playgroud)
不知道为什么默认情况下没有添加它。请注意,使用::
over的原因0.0.0.0
是它也::
适用于 IPv6(在 mySQL 手册中提到,但在 mariaDB 手册中没有提到)。
这也修复了 telnet:
mint@mint-VirtualBox ~ $ telnet 128.199.203.208 3306
Trying 128.199.203.208...
Connected to 128.199.203.208.
Run Code Online (Sandbox Code Playgroud)
网络输出现在是:
[user]@popfreq:/etc/mysql$ sudo netstat -ntlup | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 17609/mysqld
Run Code Online (Sandbox Code Playgroud)
希望这对其他人有帮助。
小智 5
在遇到同样的问题(在 Debian Stretch 上)并且已经尝试了这里提到的所有解决方案但没有成功之后,我终于从我刚刚发布重要部分的地方找到了这个:
编辑/etc/mysql/mariadb.conf.d/50-server.cnf,注释bind-address,并添加sql-mode语句:
[...]
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
sql-mode="NO_ENGINE_SUBSTITUTION"
[...]
Run Code Online (Sandbox Code Playgroud)
并且-它起作用了。
归档时间: |
|
查看次数: |
29170 次 |
最近记录: |