mysql   用戶授權


1.給管理員設置密碼

####################################################################################

在命令行界面,關鍵字mysqladmin,password "密碼" 要用引號引起來,因爲密碼的類型爲char 字符型

[root@localhost cd]# mysqladmin -uroot -hlocalhost password "123456"

[root@localhost cd]# mysql -uroot -hlocalhost -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.0.95 Source distribution


Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


####################################################

2.密碼忘記的時候怎麼辦 //改方法要重啓數據庫,影響很大,所以要妥善管理自己的密碼

①、編輯配置文件,然後重啓服務

vim /etc/my.cnf

skip-grant-table //添加以上命令,跳過授權表


重啓服務

service mysqld restart


②、登陸mysql,手動更新mysql.user的root密碼

mysql

mysql> update mysql.user set password=password("123") where user="root" and host="localhost";


mysql> flush privileges;// 對mysql庫下的表做手動操作,需要 flush privileges;


mysql>quit


③、重新進入主配置文件,刪除主配置文件上 skip-grant-table,重啓服務,以新密碼登錄



##############################################################################

用戶授權

① mysql.user 保存數據庫的授權用戶信息,可以通過以下命令查看

然後再通過show grants for 用戶名@“客戶端地址”查看具體的權限信息


另外

mysql.db 保存授權用戶對某個庫的權限信息

mysql.columns_priv 保存對錶中字段的授權信息

mysql.tables_priv 保存對錶的授權信息


mysql> select user,host,password from mysql.user;

+--------+-----------------------+------------------+

| user | host | password |

+--------+-----------------------+------------------+

| root | localhost | 565491d704013245 |

| root | localhost.localdomain | |

| root | 127.0.0.1 | |

| | localhost | |

| | localhost.localdomain | |

| user_1 | % | 773359240eb9a1d9 |

| user_2 | % | 773359240eb9a1d9 |

+--------+-----------------------+------------------+


mysql> show grants for user_1@"%";

+-------------------------------------------------------------------------------------------------------+

| Grants for user_1@% |

+-------------------------------------------------------------------------------------------------------+

| GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'user_1'@'%' IDENTIFIED BY PASSWORD '773359240eb9a1d9' |

+-------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)




② 授權命令

grant 權限列表 on 數據庫名 to 用戶名@"客戶端地址"

identified by "密碼" with grant option;

########################################################################


允許使用當前數據庫服務器的管理員從網絡中的192.168.10.10 連接數據庫服務器,密碼是888,對數據庫服務器上的所有所有表有完全權限且有授權的權限。


grant all on *.* to root@"192.168.10.10" identified by "888" with grant option;


####################################################################################

identified by "密碼"

1 指定授權用戶密碼

2 可選項 如不設置此選項 授權用戶登錄服務器的時候就沒有密碼



with grant option

1 授予授權用戶有授權的權限,自己有什麼樣的權限 就可以授予其他用戶什麼樣 的權限

2 可選項 如不設置此選項 授權用戶就沒有授權的權限


③ 撤銷授權

revoke 權限列表 on 數據庫 from 用戶名@"客戶端地址";



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章