目前使用的user及host:
mysql> select USER(); +----------------+ | USER() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec)
新增使用者
mysql5先前版本直接使用INSERT 向mysql 表中插入mysql使用者了,mysql5之後不可以這樣操作
mysql> insert into mysql.user(Host,User,Password) values('localhost','test_user',password('123123')); ERROR 1062 (23000): Duplicate entry 'localhost-test_user' for key 'PRIMARY'
增加使用者{授予使用者指定資料表權限[使用GRANT 指令對使用者進行對應授權]}
mysql> GRANT all privileges ON table1.* TO 'test_user'@'localhost' IDENTIFIED BY '123123' WITH GRANT OPTION; Query OK, 0 rows affected (0.02 sec)
IDENTIFIED BY 指定使用者的登入密碼
##ALL PRIVILEGES 是表示所有權限,也可以使用select、update 等權限 *.\ 中前面的*號用來指定資料庫名,後面的*號用來指定表名 #TO 表示將權限賦予某個用戶 ON 用來指定權限針對哪些函式庫和表 'test_user'@'localhost' 表示test_user用戶,@後面接限制的主機,可以是IP、IP段、網域名稱以及%,%表示任何地方 WITH GRANT OPTION 這個選項表示該使用者可以將自己擁有的權限授權給別人 需要刷新系統權限表[flush privilege]該使用者才能生效登入mysql> flush privileges;
mysql> drop user 'test_user'@'localhost';
mysql> SHOW GRANTS; +----------------------------------------------------------------------------------------------------------------------------------------+ | Grants for root@localhost | +----------------------------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '\*E56A114692FE0DE073F9A1DD68A00EEB9703F3F1' WITH GRANT OPTION | | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION | +----------------------------------------------------------------------------------------------------------------------------------------+
mysql> show grants for 'test_user'@'localhost' +------------------------------------------------------------------------------------------------------------+ | Grants for test_user@localhost | +------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'test_user'@'localhost' IDENTIFIED BY PASSWORD '\*E56A114692FE0DE073F9A1DD68A00EEB9703F3F1' | | GRANT ALL PRIVILEGES ON table1.* TO 'test_user'@'localhost' WITH GRANT OPTION | +------------------------------------------------------------------------------------------------------------+
mysql> rename user 'test_user'@'localhost' to 'bb'@'localhost';
mysql> SET PASSWORD FOR 'test_user'@'localhost' = PASSWORD('123456');
/usr/bin$ mysqladmin -utest_user -p123456 password 123123 mysqladmin: Can't turn off logging; error: 'Access denied; you need (at least one of) the SUPER privilege(s) for this operation'
mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set PASSWORD = PASSWORD('123123') where user = 'test_user'; Query OK, 1 row affected (0.04 sec) Rows matched: 1 Changed: 1 Warnings: 0
MySQL教學》
以上是Mysql使用者管理相關知識介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!