Linux mysql连接服务器器下 给mysql用户受权限 提示0行受影响 授权失败 怎么解决?

MySQL 用户与权限管理
第2页_数据库技术_Linux公社-Linux系统门户网站
你好,游客
MySQL 用户与权限管理
来源:Linux社区&
作者:Leshami
3、使用grant授予权限
--grant命令语法root@localhost[mysql]& help grantName: 'GRANT'Description:Syntax:GRANT& & priv_type [(column_list)]& & & [, priv_type [(column_list)]] ...& & ON [object_type] priv_level& & TO user_specification [, user_specification] ...& & [REQUIRE {NONE | ssl_option [[AND] ssl_option] ...}]& & [WITH with_option ...]
GRANT PROXY ON user_specification& & TO user_specification [, user_specification] ...& & [WITH GRANT OPTION]
object_type:& & TABLE& | FUNCTION& | PROCEDURE
priv_level:& & *& | *.*& | db_name.*& | db_name.tbl_name& | tbl_name& | db_name.routine_name
user_specification:& & user& & [& & & | IDENTIFIED WITH auth_plugin [AS 'auth_string']& & & & IDENTIFIED BY [PASSWORD] 'password'& & ]
如何授权& a、需要指定授予哪些权限& b、权限应用在那些对象上(全局,特定对象等)& c、授予给哪个帐户& d、可以指定密码(可选项,用此方式会自动创建用户)
授权权限的范围:& ON *.*& ON& db_name.*& ON& db_name.table_name& ON& db_name.table_name.column_name& ON& db_name.routine_name
--权限一览表,我们直接查询root账户所有的权限,如下--mysql的权限相对于而言,相对简单,而且也没有涉及到角色方面的定义与配置root@localhost[(none)]& select * from mysql.user where user='root' and host='localhost'\G *************************** 1. row ***************************& & & & & & & & & Host: localhost& & & & & & & & & User: root& & & & & & & Password: & & & & &
Select_priv: Y& & & & &
Insert_priv: Y& & & & &
Update_priv: Y& & & & &
Delete_priv: Y& & & & &
Create_priv: Y& & & & & &
Drop_priv: Y& & & & &
Reload_priv: Y& & & &
Shutdown_priv: Y& & & & & Process_priv: Y& & & & & &
File_priv: Y& & & & & & Grant_priv: Y& & &
References_priv: Y& & & & & & Index_priv: Y& & & & & & Alter_priv: Y& & & & & Show_db_priv: Y& & & & & & Super_priv: Y&Create_tmp_table_priv: Y& & & Lock_tables_priv: Y& & & & & Execute_priv: Y& & &
Repl_slave_priv: Y& & & Repl_client_priv: Y& & & Create_view_priv: Y& & & & Show_view_priv: Y&
Create_routine_priv: Y& & Alter_routine_priv: Y& & & Create_user_priv: Y& & & & & & Event_priv: Y& & & & & Trigger_priv: YCreate_tablespace_priv: Y& & & & & & & ssl_type: & & & & & & ssl_cipher: & & & & &
x509_issuer: & & & & & x509_subject: & & & &
max_questions: 0& & & & &
max_updates: 0& & &
max_connections: 0& max_user_connections: 0& & & & & & & & plugin: &authentication_string: 1 row in set (0.00 sec)
--说明,本文中描述的mysql提示符为user@hostname[(dbname)],不同的帐户,不同的主机登录会显示不同。--其次,不同的提示符下所代表的用户身份及权限。--查看当前的连接用户root@localhost[(none)]& select current_user();+----------------+| current_user() |+----------------+| root@localhost |+----------------+
--查看当前帐户的权限root@localhost[(none)]&& --该账户用于最高权限,带有WITH GRANT OPTION+---------------------------------------------------------------------+| Grants for root@localhost& & & & & & & & & & & & & & & & & & & & &
|+---------------------------------------------------------------------+| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION || GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION& & & & |+---------------------------------------------------------------------+
11b:~ # mysql -ufred -pEnter password:
fred@localhost[(none)]&+------------------------------------------+| Grants for fred@localhost& & & & & & & & |+------------------------------------------+| GRANT USAGE ON *.* TO 'fred'@'localhost' |+------------------------------------------+
--下面使用root账户给fred赋予权限all privilegesroot@localhost[(none)]& grant all privileges on *.* to 'fred'@'localhost';Query OK, 0 rows affected (0.01 sec)
root@localhost[(none)]&Query OK, 0 rows affected (0.00 sec)
fred@localhost[(none)]&+---------------------------------------------------+| Grants for fred@localhost& & & & & & & & & & & &
|+---------------------------------------------------+| GRANT ALL PRIVILEGES ON *.* TO 'fred'@'localhost' |+---------------------------------------------------+
fred@localhost[(none)]& use tempdb
fred@localhost[tempdb]& create table tb_isam(id int,value varchar(20)) engine=Query OK, 0 rows affected (0.10 sec)
fred@localhost[tempdb]& insert into tb_isam values (1,'jack'),(2,'robin');Query OK, 2 rows affected (0.00 sec)Records: 2& Duplicates: 0& Warnings: 0
fred@localhost[tempdb]&
--下面的授权收到了错误提示,不能授权fred@localhost[tempdb]& grant select on tempdb.* to 'frank'@'%';ERROR ): Access denied for user 'fred'@'localhost' to database 'tempdb'
--下面从root session来给之前创建的frank授权--授予frank在数据库tempdb上所有对象的select权限root@localhost[(none)]& grant select on tempdb.* to 'frank'@'%';Query OK, 0 rows affected (0.00 sec)
--更新cache中的权限root@localhost[(none)]&Query OK, 0 rows affected (0.00 sec)
--从另外的主机使用frank账户登录suse11a:~ # mysql -ufrank -p -h172.16.6.89Enter password:
--此时frank,此时已经可以访问了tempdb上的表tb_isamfrank@172.16.6.89[(none)]& select * from tempdb.tb_+------+-------+| id&
| value |+------+-------+|& & 1 | jack& ||& & 2 | robin |+------+-------+
frank@172.16.6.89[(none)]&+------------------------------------------------------------------------------------------------------+| Grants for frank@%& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &
|+------------------------------------------------------------------------------------------------------+| GRANT USAGE ON *.* TO 'frank'@'%' IDENTIFIED BY PASSWORD '*63DAAEB96570FA4DBE154711BEB361' || GRANT SELECT ON `tempdb`.* TO 'frank'@'%'& & & & & --可以看到多出了select权限& & & & & & & & & & & &
|+------------------------------------------------------------------------------------------------------+
--下面是一个授予最大权限的例子,授予的同时会自动创建用户,由于我们没有设置密码,所以password列查询结果为空root@localhost[(none)]& grant all privileges on *.* to 'jack'@'localhost';&
Query OK, 0 rows affected (0.00 sec)& & --第一个*号代表任意数据库,第二个*号代表数据库上的任意对象
root@localhost[(none)]& select user,host,Password from mysql.user where user='jack';+------+-----------+----------+| user | host& & & | Password |+------+-----------+----------+| jack | localhost |& & & & & |+------+-----------+----------+
suse11b:~ # mysql -ujack -p -h localhostEnter password:
jack@localhost[(none)]& show grants for current_ --该方式等同于show grants,查看自身权限+---------------------------------------------------+| Grants for jack@localhost& & & & & & & & & & & &
|+---------------------------------------------------+| GRANT ALL PRIVILEGES ON *.* TO 'jack'@'localhost' |+---------------------------------------------------+
--在当前session下查看其它用户的权限,注,当前session登陆的用户也需要有权限才能查看其它用户权限jack@localhost[(none)]& show grants for 'frank'@'%';+------------------------------------------------------------------------------------------------------+| Grants for frank@%& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &
|+------------------------------------------------------------------------------------------------------+| GRANT USAGE ON *.* TO 'frank'@'%' IDENTIFIED BY PASSWORD '*63DAAEB96570FA4DBE154711BEB361' || GRANT SELECT ON `tempdb`.* TO 'frank'@'%'& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & |+------------------------------------------------------------------------------------------------------+
--下面演示基于对象列级别的授权--首先revoke之前的select权限root@localhost[(none)]& revoke select on tempdb.* from 'frank'@'%';Query OK, 0 rows affected (0.00 sec)
fred@localhost[tempdb]& create table tb_user as select * from mysql.Query OK, 9 rows affected (0.15 sec)Records: 9& Duplicates: 0& Warnings: 0
fred@localhost[tempdb]& grant select(user,host),update(host) on tempdb.tb_user to 'frank'@'%';ERROR ): GRANT command denied to user 'fred'@'localhost' for table 'tb_user' --授权失败
--下面使用root来授权root@localhost[(none)]& grant select(user,host),update(host) on tempdb.tb_user to 'frank'@'%';Query OK, 0 rows affected (0.00 sec)
root@localhost[(none)]&Query OK, 0 rows affected (0.00 sec)
--下面检查一下frank所拥有的权限root@localhost[(none)]& show grants for 'frank';+------------------------------------------------------------------------------------------------------+| Grants for frank@%& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &
|+------------------------------------------------------------------------------------------------------+| GRANT USAGE ON *.* TO 'frank'@'%' IDENTIFIED BY PASSWORD '*63DAAEB96570FA4DBE154711BEB361' || GRANT SELECT (user, host), UPDATE (host) ON `tempdb`.`tb_user` TO 'frank'@'%'& & & & & & & & & & & & |+------------------------------------------------------------------------------------------------------+
--下面使用frank身份来验证所授予的权限frank@172.16.6.89[(none)]& desc tempdb.tb_+-------+----------+------+-----+---------+-------+| Field | Type& &
| Null | Key | Default | Extra |+-------+----------+------+-----+---------+-------+| Host& | char(60) | NO&
|| User& | char(16) | NO&
|+-------+----------+------+-----+---------+-------+
frank@172.16.6.89[(none)]& select * from tempdb.tb_&
--访问时不支持通配符,必须指定列名 ERROR ): SELECT command denied to user 'frank'@'suse11a.site' for table 'tb_user'
frank@172.16.6.89[(none)]& select host,user from tempdb.tb_user where user='frank';+------+-------+| host | user& |+------+-------+| %& & | frank |+------+-------+
--需要注意的是,如果你的对象创建在test相关数据库下,权限限制可能会失效。--下面这个查询用于查看db的授权表root@localhost[(none)]& select host,db,user from mysql.+------+---------+------+| host | db& & & | user |+------+---------+------+| %& & | test& & |& & & || %& & | test\_% |& & & |+------+---------+------+
--根据前面的权限授予,列host可以被更新,而列user不行,如下面的2条SQL语句执行的结果frank@172.16.6.89[(none)]& update tempdb.tb_user set host='localhost' where user='frank';Query OK, 1 row affected (0.12 sec)Rows matched: 1& Changed: 1& Warnings: 0
frank@172.16.6.89[(none)]& update tempdb.tb_user set user='jason' where user='jack';ERROR ): UPDATE command denied to user 'frank'@'suse11a.site' for column 'user' in table 'tb_user'
--关于WITH GRANT OPTIONroot@localhost[(none)]&&
--注意root下有WITH GRANT OPTION+---------------------------------------------------------------------+| Grants for root@localhost& & & & & & & & & & & & & & & & & & & & &
|+---------------------------------------------------------------------+| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION || GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION& & & & |+---------------------------------------------------------------------+
root@localhost[(none)]& show grants for 'jack'@'localhost'; --注意jack下没有WITH GRANT OPTION+---------------------------------------------------+& & &
--这就是前面为什么用户自身创建的对象而无法授权的问题| Grants for jack@localhost& & & & & & & & & & & &
+---------------------------------------------------+| GRANT ALL PRIVILEGES ON *.* TO 'jack'@'localhost' |+---------------------------------------------------+&SPAN style="FONT-FAMILY: Courier New"&&&&&&&&& &/SPAN&2
相关资讯 & & &
& (08月29日)
& (07/28/:32)
& (08/10/:30)
& (06/01/:26)
图片资讯 & & &
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款如何取得linux服务器的系统时间,我用的是Mysql的数据库
[问题点数:20分,结帖人jamescheng]
如何取得linux服务器的系统时间,我用的是Mysql的数据库
[问题点数:20分,结帖人jamescheng]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
2001年10月 PowerBuilder大版内专家分月排行榜第二
2002年2月 PowerBuilder大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。当前位置: &
& linux下 mysql 忘记root用户密码解决办法
[] [] [] []linux下 mysql 忘记root用户密码解决办法
责任编辑:作者:网络 佚名&&
  【IT168 】linux下忘记了mysql的root用户密码解决办法:
  一、以系统的root用户(什么,你的系统的root用户密码也忘了。那只好看我另外一篇linux下忘记root用户的解决办法了先解决这个问题)登陆系统,进入终端
  [root@localhost /]#
  二、杀掉mysql进程
  方法1、[root@localhost /]#killall mysqld
  方法2、[root@localhost /]#ps -aux& //查看所有进程,找到mysql进程的pid
  [root@localhost /]#kill pid&& //pid是mysql的进程号
  三、用--skip-grant-tables参数启动mysqld
  [root@localhost /]#/usr/local/mysql/bin/mysqld_safe --skip-grant-tables&&
  // 其中/usr..../bin是我的mysql安装目录
  [root@localhost /]#/usr/local/mysql/bin/mysql& //进入mysql
  mysql& use mysql&& //切换到mysql database
  mysql& UPDATE user SET password=password('123456') WHERE user='root';
  //将root密码该为123456了
  四、注意事项
  The full command to load MySQL like this is:
  mysqld_safe --skip-grant-tables --autoclose
  (Editor's Note: Our technical reviewer found that he had to launch the mysqld_safe command
  without the '--autoclose' flag, otherwise the daemon never started.)
  这是国外网站说的,我没用autoclosa也成功了
  但是我在执行/usr/local/mysql/bin/mysqld_safe --skip-grant-tables&即出现错误提示:
  ./mysqld_safe
  starting mysqld daemon with databases from /usr/local/var
  STOPPING server from pid file /usr/local/var/localhost.localdomain.pid
  mysqld& ended
  然后进入/usr/local/var/
  vi ./localhost.localdomain.err 内容如下:
  :02:59 mysqld started
  :03:00 InnoDB:Operating system error number 13 in a file operation.
  InnoDB:The error means mysqld does not have the access rights to
  InnoDB:the directory.
  InnoDB:File name ./ibdata1
  InnoDB:File operation call:'create'.
  InnoDB:Cannot continue operation.
  :03:00 mysqld ended
  怀疑是./var目录的访问权限,故如下操作:
  chmod 777 ./var
  然后重新执行后台,仍出以上错误,但在localhost.localdomain.err文件中的错误信息已改为找不到一个叫做
  help.*的文件了(这个文件名我记不得了)
  这是因为我的mysql安装目录的读写权限是这样造成的
  mysql安装目录属于用户root,但是群组是mysql的
  把群组也改为root即可。
【内容导航】
史上最详细DELL网购天书 优惠信息请致电800-858-2903
本文欢迎转载,转载请注明:转载自IT168 [
本文链接:
服务器专区最新文章&&
服务器相关文章&&[本文关键字:mysql ]
服务器专区热点关注
服务器专区热评文章
论坛相关讨论&&
装机必备软件
服务器专区精彩专题
服务器推荐
All Rights Reserved. 北京皓辰网域网络信息技术有限公司. 版权所有 京ICP证:060528号}

我要回帖

更多关于 mysql主从服务器 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信