新闻资讯

新闻资讯 行业动态

MYSQL添加远程用户或允许远程访问三种方法

编辑:008     时间:2020-02-15

方法一
添加远程用户admin密码为password
GRANT ALL PRIVILEGES ON *.* TO admin@localhost IDENTIFIED BY \'password\' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO admin@\"%\" IDENTIFIED BY \'password\' WITH GRANT OPTION;
mysql教程添加远程用户或允许远程访问三种方法
用root用户登陆,然后:
grant all privileges on *.* to 创建的用户名 @"%" identified by "密码";
flush privileges;   * 刷新刚才的内容*
格式:grant 权限 on 数据库教程名.表名 to 用户@登录主机 identified by "用户密码";
            @ 后面是访问mysql的客户端ip地址(或是 主机名) % 代表任意的客户端,如果填写 localhost 为
本地访问(那此用户就不能远程访问该mysql数据库了)。
同时也可以为现有的用户设置是否具有远程访问权限。如下:
use mysql;
update db set host = '%' where user = '用户名'; (如果写成 host=localhost 那此用户就不具有远程访问权限)
flush privileges;
grant all privileges on *.* to 'myuser'@'%' identified by 'mypassword' with grant option;

方法二
1.  使用grant语句添加:首先在数据库本机上用root用户
登录mysql(我是用远程控制linux服务器,相当于在服务器本机登录mysql了),然后输入:
mysql>grant all privileges on *.* to admin@localhost identified by 'something' with grant option;
添加一个用户admin并授权通过本地机(localhost)访问,密码"something"。
 mysql>grant all privileges on *.* to admin@"%" identified by 'something' with grant option;
添加一个用户admin并授权可从任何其它主机发起的访问(通配符%)。使用这一条语句即可。
2.使用insert语句:
mysql>insert into user values('%','admin',password('something'), 'y','y','y','y','y','y',
'y','y','y','y','y','y','y','y')
   用户信息可在mysql数据库中的users表中查看,这里不在介绍了就。数清y的个数哦。
   好了,使用admin帐号连接试试看,我是屡试屡成功哦,呵呵!

方法三
添加远程用户admin密码为password
grant all privileges on *.* to admin@localhost identified by 'password' with grant option;
grant all privileges on *.* to admin@"%" identified by 'password' with grant option;

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

回复列表

相关推荐