登录mysql数据库
mysql -u root -p
切换mysql数据库
use mysql
查看数据库当前有访问权限的信息
SELECT User, Password, Host FROM user;
mysql> SELECT User, Password, Host FROM user;
+------+-------------------------------------------+-----------+
| User | Password | Host |
+------+-------------------------------------------+-----------+
| root | *D0FAD46F5E73405CDBA17B663D1648C5AAC6D465 | localhost |
| root | *A528827CA1B493E1175FDF498E0651E917BE4B10 | lhk.mysql |
| root | *A528827CA1B493E1175FDF498E0651E917BE4B10 | 127.0.0.1 |
| root | *A528827CA1B493E1175FDF498E0651E917BE4B10 | ::1 |
+------+-------------------------------------------+-----------+
设置访问权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'XXXXX' WITH GRANT OPTION;
其中"*.*"代表所有资源所有权限, “'root'@%”其中root代表账户名,%代表所有的访问地址,也可以使用一个唯一的地址进行替换,只有一个地址能够访问。如果是某个网段的可以使用地址与%结合的方式,如10.0.42.%。IDENTIFIED BY 'root',这个root是指访问密码。WITH GRANT OPTION允许级联授权。
刷新访问权限表(不要忘了)
FLUSH PRIVILEGES;
转自:
https://blog.csdn.net/zhazhagu/article/details/81064406