我已经在我的本地机器上安装了MySQL Community Edition 5.5,我想允许远程连接,这样我就可以从外部源连接。
我该怎么做呢?
我已经在我的本地机器上安装了MySQL Community Edition 5.5,我想允许远程连接,这样我就可以从外部源连接。
我该怎么做呢?
当前回答
如果mysqld有一个绑定地址设置为环回/本地地址(例如127.0.0.1),服务器将无法从远程主机到达,因为环回接口无法从任何远程主机到达。
将此选项设置为0.0.0.0(::对于IPv4+6)以接受来自任何主机的连接,如果您希望只允许在一个接口上连接,则将该选项设置为另一个外部可达地址。
源
其他回答
MySQL 8不再允许您使用GRANT命令创建用户。您需要首先创建用户。
CREATE USER 'root'@'%' IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
有时需要在Windows上使用PC名
第一步)把mysql的配置文件:
mysqld.cnf SET bind-address= 0.0.0.0
(让recbe连接tcp/ip)
第二步)让用户在mysql,表用户,与pc在windows属性的名称,而不是ip
远程登录的所有流程。默认关闭远程登录。你需要手动打开所有ip..来访问所有ip
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';
特定的Ip
GRANT ALL PRIVILEGES ON *.* TO 'root'@'your_desire_ip' IDENTIFIED BY 'password';
然后
flush privileges;
您可以检查您的用户主机和密码
SELECT host,user,authentication_string FROM mysql.user;
现在你的责任就是改变这一切
bind-address = 127.0.0.1
你可以找到这个
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
如果你在那里找不到这个,那就试试这个
sudo nano /etc/mysql/my.cnf
在此评论
#bind-address = 127.0.0.1
然后重新启动Mysql
sudo service mysql restart
现在享受远程登录
关闭链接/etc/mysql/mysql.conf.d/mysqld.cnf或/etc/mysql/my.cnf的注释:
bind-address = 127.0.0.1 =>> #bind-address = 127.0.0.1
修改主机名以便所有机器都可以访问它,在本地运行这个SQL命令:
UPDATE mysql.user SET Host='%' WHERE Host='localhost' AND User='root';
FLUSH PRIVILEGES;
重新启动服务:
sudo service mysql restart
打开mysql端口:
sudo ufw allow 3306
启用远程根访问可能是危险的。如果您要设置具有更严格权限的用户帐户,则更可取。以下三个步骤可以做到这一点。
Ensure that the line starting with bind-address ... is at least commented out in your my.ini or my.cnf file. If it doesn't exist, move on. You can find this file in C:\ProgramData\MySQL\MySQL Server 8.0 on Windows. Afterwards, check that the user account you are establishing the connection with does not have localhost in the Limit to Hosts Matching field. While it isn't recommended, you can instead put % in that field for testing purposes. You can do this by opening a local connection to the server with MySQL Workbench, then going to Server>Users and Privileges from the menu bar and finding the user account you want to connect with.
“限制主机匹配”字段是不允许您连接非本地。也就是说,它将接受的连接限制为一个IP地址模式。理想情况下,您应该从静态IP地址或子网访问MySQL服务器,这样您就可以尽可能地限制。
显然,您的防火墙应该允许MySQL服务器应用程序通过您想要的端口进行通信。您和服务器之间的物理网络设备应该允许在您想要连接的端口上进行通信。(通常端口为3306)