mysql给root开启远程访问权限

1、打开mysql.exe(MySQL Command Line Client),输入密码

2、输入:use mysql;

3、查询host输入: select user,host from user;

4、创建host(如果有”%”这个host值,则跳过这一步)

如果没有”%”这个host值,就执行下面这两句:
mysql> update user set host=’%’ where user=’root’;
mysql> flush privileges;

5、授权用户

(1)任意主机以用户root和密码pwd连接到mysql服务器

mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘pwd’ WITH GRANT OPTION;
mysql> flush privileges;

(2)指定IP为(如192.168.1.100)的主机以用户tuser和密码tpwd连接到mysql服务器

mysql> GRANT ALL PRIVILEGES ON *.* TO ‘tuser’@’192.168.1.100’ IDENTIFIED BY ‘tpwd’ WITH GRANT OPTION;
mysql> flush privileges;

mysql> USE mysql; -- 切换到 mysql DB

Database changed

mysql> SELECT User, Password, Host FROM user; -- 查看现有用户,密码及允许连接的主机

+------+----------+-----------+
| User | Password | Host      |
+------+----------+-----------+
| root |          | localhost |
+------+----------+-----------+
1 row in set (0.00 sec)

 

mysql> -- 只有一个默认的 root 用户, 密码为空, 只允许 localhost 连接
12
mysql> -- 下面我们另外添加一个新的 root 用户, 密码为空, 只允许 192.168.1.100 连接

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100' IDENTIFIED BY '' WITH GRANT OPTION;

 

mysql> -- @'192.168.1.100'可以替换为@‘%’就可任意ip访问,当然我们也可以直接用 UPDATE 更新 root 用户 Host, 但不推荐, SQL如下:

mysql> -- UPDATE user SET Host='192.168.1.100' WHERE User='root' AND Host='localhost' LIMIT 1;

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

相关文章

  • 没有相关文章 :(
0 条评论
发表一条评论