3.修改root登录权限(强烈不建议如此做,否则会带来严重的安全风险)
mysql> update mysql.user set host = '%' where user = 'root';
或者
mysql> grant select,update,insert,delete on test.* to root@localhost identified by "123456";
或者
mysql> grant select,update,insert,delete on test.* to root@% identified by "123456";
或者
mysql> grant select,update,insert,delete on test.* to root@ip identified by "123456";
flush privileges; --写入权限表
这样就可以通过root和密码123456来访问了。
4.上面的操作风险太大,不建议,我们应该新创建一个用户:
mysql> grant select,update,insert,delete on test.* to scott@localhost identified by "123456";
注意:
如果还是不行,则重启mysql:
service mysqld stop;
service mysqld start;
service mysqld status; --查看状态
有时候通过 % 不一定能访问,会发生:
SQLException: access denied for @'10.44.55.195.' (using password: no)
则上面的语句可以改为:
mysql> grant select,update,insert,delete on test.* to scott@10.44.55.195 identified by "123456";
(10.44.55.195其实是客户端的ip)
但是,优先用%。务必务必!
取消赋权的语句是:
revoke all on mysql.* from root@10.44.55.195;