mysql远程连接

来源:互联网 发布:openstack windows 编辑:程序博客网 时间:2024/06/11 16:21

错误现象:
连接远端的MYSQL出现1045错误:”Access denied for user root@162.105.67.62

如果要远程登录该mysql服务器的话,就需要在服务器端新建一个普通权限的用户,新建用户使用如下命令:

create user 'duan'@'localhost' identified by '123';grant all privileges on *.*  to duan@localhost identified by '123'with grant option;FLUSH PRIVILEGES;use mysql;FLUSH PRIVILEGES;

这句命令的意思是:新建用户duan,并且只允许该用户在本地(localhost)登录,密码是123,并且赋予它全部权限。现在该duan用户,已经可以登录mysql了,但是也还是只能本地登录。

若要duan用户可以远程登录mysql,则还需要如下命令:

 mysql> update user set host = '%' where user = 'duan'; mysql> flush privileges;  ##注意:这句必须执行

此时,在客户端,新建一个连接,用上面的用户名和密码,ip采用服务器端的ip地址即可远程连接服务器端的MySQL。

0 0