配置MySQL以进行本地和远程访问 [英] Configure MySQL for local and remote access

查看:507
本文介绍了配置MySQL以进行本地和远程访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySQL服务器版本:Raspberry Pi上的10.1.23-MariaDB-9 + deb9u1 Raspbian 9.0.

I'm using MySQL server version: 10.1.23-MariaDB-9+deb9u1 Raspbian 9.0 on a Raspberry Pi.

这是我的/etc/mysql/my.cnf:

# 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/

#bind-address = 0.0.0.0

我已经尝试过了:

sudo mysql_secure_installation
Change root password: y
Password
Retyped password
Remove anonymous users: y
Disallow root login remotely: n
Remove test database: y
Reload priviledges: y

CREATE USER 'root'@'%.%.%.%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%.%.%.%' WITH GRANT OPTION;
FLUSH PRIVILEDGES;
service mysql restart

my.cnf中,在注释了绑定地址的情况下,我可以使用SQL Workbench从localhost进行访问,但是不能从远程主机进行访问.

In my.cnf, with bind-address commented, I can access from localhost, but not from remote host using SQL Workbench.

在未注释绑定地址的情况下,我无法从localhost访问,但是可以使用SQL Workbench从远程主机进行访问,例如:

With bind-address uncommented, I cannot access from localhost, but I can access from remote host using SQL Workbench, e.g.:

mysql -u root
mysql: unknown variable 'bind-address=0.0.0.0'

这是我的用户表:

MariaDB [(none)]> select user, host, password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *054D119DEAD56E226D8356557796BFA72E71BA40 |
| root | %.%.%.%   | *054D119DEAD56E226D8356557796BFA72E71BA40 |
| root | %         | *054D119DEAD56E226D8356557796BFA72E71BA40 |
+------+-----------+-------------------------------------------+

如何配置服务器以允许从任何IP对root进行本地和远程访问?

How do I configure the server to allow local and remote access for root from any IP?

推荐答案

使用[mysqld]在 bind-address = 0.0.0.0 上添加一行,例如:

Add a line over bind-address = 0.0.0.0 with [mysqld] like:

[mysqld]
bind-address = 0.0.0.0

在您的情况下,服务器和本地客户端都会读取绑定地址,并且客户端要连接到IP 0.0.0.0

In your case both, the server and the local client, reads the bind address and the client want to connect to the IP 0.0.0.0

这篇关于配置MySQL以进行本地和远程访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆