资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

mysql怎么授权 mysql的授权语句

如何设置mysql用户的权限

1、创建新用户

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的钦北网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

通过root用户登录之后创建

grant all privileges on *.* to testuser@localhost identified by "123456" ;//创建新用户,用户名为testuser,密码为123456 ;

grant all privileges on *.* to testuser@localhost identified by "123456" ;//设置用户testuser,可以在本地访问mysql

grant all privileges on *.* to testuser@"%" identified by "123456" ; //设置用户testuser,可以在远程访问mysql

flush privileges ;//mysql 新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效

2、设置用户访问数据库权限

grant all privileges on test_db.* to testuser@localhost identified by "123456" ;//设置用户testuser,只能访问数据库test_db,其他数据库均不能访问 ;

grant all privileges on *.* to testuser@localhost identified by "123456" ;//设置用户testuser,可以访问mysql上的所有数据库 ;

grant all privileges on test_db.user_infor to testuser@localhost identified by "123456" ;//设置用户testuser,只能访问数据库test_db的表user_infor,数据库中的其他表均不能访问 ;

3、设置用户操作权限

grant all privileges on *.* to testuser@localhost identified by "123456" WITH GRANT OPTION ;//设置用户testuser,拥有所有的操作权限,也就是管理员 ;

grant select on *.* to testuser@localhost identified by "123456" WITH GRANT OPTION ;//设置用户testuser,只拥有【查询】操作权限 ;

grant select,insert on *.* to testuser@localhost identified by "123456" ;//设置用户testuser,只拥有【查询\插入】操作权限 ;

grant select,insert,update,delete on *.* to testuser@localhost identified by "123456" ;//设置用户testuser,只拥有【查询\插入】操作权限 ;

REVOKE select,insert ON what FROM testuser//取消用户testuser的【查询\插入】操作权限 ;

如何让mysql数据库允许被远程连接访问?

第一:更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改称'%'。 \x0d\x0a或者新加条记录,“host” 项为要访问的ip地址,并授权。重启mysql服务。 \x0d\x0a第二:在系统防火墙添加例外端口:3306,并允许例外。 \x0d\x0a\x0d\x0a错误提示: \x0d\x0aERROR 1130: Host '192.168.1.3is not allowed to connect to this MySQL server \x0d\x0a的解决方法: \x0d\x0a1。改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%" \x0d\x0a1.mysql -u root -pvmware\x0d\x0amysqluse mysql;\x0d\x0amysqlupdate user set host = '%where user = 'root';\x0d\x0amysqlselect host, user from user; \x0d\x0a\x0d\x0a2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。 \x0d\x0a\x0d\x0aGRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%IDENTIFIED BY 'mypasswordWITH GRANT OPTION; \x0d\x0a如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码 \x0d\x0aGRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3IDENTIFIED BY 'mypasswordWITH GRANT OPTION; \x0d\x0a\x0d\x0a3.在window自带的防火墙里的例外添加3306端口 \x0d\x0a\x0d\x0a总结: \x0d\x0amysql -u root -p \x0d\x0amysqluse mysql; \x0d\x0amysqlselect 'hostfrom user where user='root'; \x0d\x0amysqlupdate user set host = '%where user ='root'; \x0d\x0amysqlflush privileges; \x0d\x0amysqlselect 'host from user where user='root'; \x0d\x0a第一句是以权限用户root登录 \x0d\x0a第二句:选择mysql库 \x0d\x0a第三句:查看mysql库中的user表的host值(即可进行连接访问的主机/IP名称) \x0d\x0a第四句:修改host值(以通配符%的内容增加主机/IP地址),当然也可以直接增加IP地址 \x0d\x0a第五句:刷新MySQL的系统权限相关表 \x0d\x0a第六句:再重新查看user表时,有修改。。 \x0d\x0a重起mysql服务即可完成。

mysql怎么授予创建数据库的权限

MySQL命令行能否实现新建用户呢?答案无疑是肯定的。而且在使用使用MySQL命令行新建用户后,还可以为用户授予权限。

首先要声明一下:一般情况下,修改MySQL密码,授权,是需要有mysql里的root权限的。

注:本操作是在WIN命令提示符下,phpMyAdmin同样适用。

用户:phplamp

用户数据库:phplampDB

1.MySQL命令行新建用户

//登录MYSQL

@mysql -u root -p

@密码

//创建用户

mysql insert into mysql.user(Host,User,Password) values('localhost','phplamp',password('1234'));

//刷新系统权限表

mysqlflush privileges;

这样就创建了一个名为:phplamp 密码为:1234 的用户。

//退出后登录一下

mysqlexit;

@mysql -u phplamp -p

@输入密码

mysql登录成功

2.MySQL命令行为用户授权

//登录MYSQL(有ROOT权限)。我里我以ROOT身份登录.

@mysql -u root -p

@密码

//首先为用户创建一个数据库(phplampDB)

mysqlcreate database phplampDB;

//授权phplamp用户拥有phplamp数据库的所有权限

@grant all privileges on phplampDB.* to phplamp@localhost identified by '1234'; //这里需要注意,如果发现找不到用户,需要执行命令 flush privilieges;

//刷新系统权限表

mysqlflush privileges;

mysql其它操作

//如果想指定部分权限给一用户,可以这样来写:

mysqlgrant select,update on phplampDB.* to phplamp@localhost identified by '1234';

//刷新系统权限表。

mysqlflush privileges;

mysql grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’;

权限1,权限2,…权限n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14个权限。

当权限1,权限2,…权限n被all privileges或者all代替,表示赋予用户全部权限。

当数据库名称.表名称被*.*代替,表示赋予用户操作服务器上所有数据库所有表的权限。

用户地址可以是localhost,也可以是ip地址、机器名字、域名。也可以用’%'表示从任何地址连接。

‘连接口令’不能为空,否则创建失败。

例如:

mysqlgrant select,insert,update,delete,create,drop on vtdc.employee to joe@10.163.225.87 identified by ‘123′;

给来自10.163.225.87的用户joe分配可对数据库vtdc的employee表进行select,insert,update,delete,create,drop等操作的权限,并设定口令为123。

mysqlgrant all privileges on vtdc.* to joe@10.163.225.87 identified by ‘123′;

给来自10.163.225.87的用户joe分配可对数据库vtdc所有表进行所有操作的权限,并设定口令为123。

mysqlgrant all privileges on *.* to joe@10.163.225.87 identified by ‘123′;

给来自10.163.225.87的用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。

mysqlgrant all privileges on *.* to joe@localhost identified by ‘123′;

给本机用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。


当前题目:mysql怎么授权 mysql的授权语句
URL链接:http://cdkjz.cn/article/hiiphs.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220