登陆mysql数据库
mysql -u root -h localhost -p查看user表
Database changed
mysql> select user,password,host from user;
可以看到在user表中已创建的root用户。host字段表示登录的主机,其值可以用IP,也可用主机名,
1、实现远程连接(授权法)
将host字段的值改为%就表示在任何客户端机器上能以root用户登录到mysql服务器,建议在开发时设为%。
mysql> use mysql;Database changed
mysql> grant all on *.* to root@'%' identified by '密码';Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,password from user;
3 rows in set (0.00 sec)
这样机器就可以以用户名root密码root远程访问该机器上的MySql.
2、实现远程连接(改表法)
use mysql;
UPDATE user SET host='%' WHERE user='root';
删除用户
Delete FROM user Where User=" " and Host="localhost";
flush privileges;
授权表
grant all on *.* to root@'%' identified by '密码';
flush privileges;
更新用户
UPDATE user SET host='%' WHERE user='root';
flush privileges;
添加mysql用户方法
insert into mysql.user(User,Password,Host) values("root",password("密码"),"%");
flush privileges;