mysql设置允许外部ip访问
Microsoft Windows [版本 10.0.20348.3932] (c) Microsoft Corporation。保留所有权利。 C:\Users\Administrator>mysql;mysql -uroot -p 'mysql;mysql' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 C:\Users\Administrator>mysql -uroot -p Enter password: **************** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 69 Server version: 8.0.44 MySQL Community Server - GPL Copyright (c) 2000, 2025, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql; Database changed mysql> update user set host='%' where user ='root'; Query OK, 1 row affected (0.04 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.03 sec) mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION; Query OK, 0 rows affected (0.01 sec) mysql>
1. 登录进入mysql;mysql -uroot -p输入密码进入
2. 输入以下语句,进入mysql库,查看user表中root用户的访问
use mysql;
select host,user from user;
3. 更新user表中root用户域属性,'%'表示允许外部访问,如下图演示;
update user set host='%' where user ='root';
4. 执行以上语句之后再执行,FLUSH PRIVILEGES;
FLUSH PRIVILEGES;
FLUSH PRIVILEGES;命令的作用:将当前user和privilige表中的用户信息/权限设置从mysql库(MySQL数据库的内置库)中提取到内存里。MySQL用户数据和权限有修改后,希望在"不重启MySQL服务"的情况下直接生效,那么就需要执行这个命令。通常是在修改ROOT帐号的设置后,怕重启后无法再登录进来,那么直接flush之后就可以看权限设置是否生效。而不必冒太大风险。
5. 执行授权语句
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
然后外部就可以通过账户密码访问了。当然,类似于访问阿里云服务器还需要开放端口和进行防火墙设置;

浙公网安备 33010602011771号