设置权限首先要找到MySQL的bin目录,默认在C:\Program Files\MySQL\MySQL Server 8.0\bin
然后我们Win+R输入cmd打开控制台,使用cd命令到MySQL的bin目录下,执行以下操作:
1.登录数据库,然后输入密码
mysql -u root -p
2.然后打开mysql
mysql> use mysql;
3.查询host
mysql> select user,host from user;
4.创建host
mysql> update user set host='%' where user='root';
mysql> flush privileges;
5.授权用户
(1)MySQL 8.0以前版本
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypwd' WITH GRANT OPTION;
mysql> flush privileges;
(2)MySQL 8.0及之后版本 (如果host列表中已有root和%用户,则可以不执行CREATE语句)
mysql> CREATE USER 'root'@'%' IDENTIFIED BY '123456';
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
mysql> flush privileges;
以上就是mysql如何让外网访问的详细内容