在mysql用戶管理中主要講述到了關於mysql用戶增加,刪除,設置密碼,刪除及權限的設置,各位有需要了解的朋友不防進入參考。
添加用戶
本機訪問權限:mysql> GRANT ALL PRIVILEGES ON *.* TO 'username
'@'localhost'
-> IDENTIFIED BY 'password' WITH GRANT OPTION;
遠程訪問權限:mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'%'
-> IDENTIFIED BY 'password' WITH GRANT OPTION;
另外還有一種方法是直接Insert INTO user,注意這種方法之後需要 FLUSH PRIVILEGES 讓服務器重讀授權表。刪除用戶
DROP USER user;限制用戶資源
mysql> GRANT ALL ON customer.* TO 'francis'@'localhost'
-> IDENTIFIED BY 'frank'
-> WITH MAX_QUERIES_PER_HOUR 20
-> MAX_UPDATES_PER_HOUR 10
-> MAX_CONNECTIONS_PER_HOUR 5
-> MAX_USER_CONNECTIONS 2;
設置用戶密碼
命令行:shell> mysqladmin -u user_name -h host_name password "newpwd"或執行語句:mysql> SET PASSWORD FOR 'username'@'%'
= PASSWORD('password');
如果只是更改自己的密碼,則直接:mysql> SET PASSWORD = PASSWORD(‘password’);
在全局級別使用GRANT USAGE語句(在*.*)來指定某個賬戶的密碼:mysql> GRANT USAGE ON *.* TO 'username'@'%'
IDENTIFIED BY 'password';
或直接修改MySQL庫表:mysql> UPDATE user SET Password = PASSWORD('bagel')
-> WHERE Host = '%' AND User = 'francis';
mysql> FLUSH PRIVILEGES;
關於加密
mysql> select PASSWORD('password');
+-------------------------------------------+
| PASSWORD('password') |
+-------------------------------------------+
| *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
+-------------------------------------------+
1 row in set (0.00 sec)
mysql> select MD5('hello');
+----------------------------------+
| MD5('hello') |
+----------------------------------+
| 5d41402abc4b2a76b9719d911017c592 |
+----------------------------------+
1 row in set (0.00 sec)
mysql> select SHA1('abc');
-> 'a9993e364706816aba3e25717850c26c9cd0d89d'
SHA1()是為字符串算出一個 SHA1 160比特檢查和,如RFC 3174 (安全散列算法)中所述。