步骤一:登录数据库
1 mysql -u root -pvmwaremysql>use mysql;
步骤二:
一. 方法一:更新mysql库下user表的root条目
局域网段(特定IP):
1 mysql>update user set host = ‘192.168.0.49‘ where user = ‘root‘;
全网访问:
1 mysql>update user set host = ‘%‘ where user = ‘root‘;
二.方法二:直接添加一条语句也行
局域网段(特定IP):
1 mysql>insert into user (host,user,password) values(‘192.168.0.50‘,‘root‘,password(‘123‘));
全网访问:
1 mysql>insert into user (host,user,password) values(‘%‘,‘root‘,password(‘123‘));
三. 方法三
格式如下:
1 GRANT ALL PRIVILEGES ON *.* TO ‘myuser‘@‘%‘IDENTIFIED BY ‘mypassword‘ WITH GRANT OPTION;
范例:
局域网段(特定IP):
1 grant all privileges on *.* to ‘root‘@‘192.168.0.51‘identified by ‘123‘ with grant option;
全网访问:
1 grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123‘ with grant option;
备注:by后面的‘ ‘里的密码可以与服务器端的密码不通,如root在服务器端是123456而by后面的密码可以是123。客户端远程访问用密码123,服务器登录仍然用123456。
步骤三:授权刷新(可以直接重启服务器)
1 mysql>FLUSH PRIVILEGES
来自 <https://www.cnblogs.com/hfdp/p/6088288.html>
原文地址:https://www.cnblogs.com/buyz/p/10940583.html
时间: 2024-10-03 01:13:53