linux mysql增加使用者,刪除使用者,以及使用者許可權
阿新 • • 發佈:2019-01-04
一些基本的命令:
登入:
mysql -u username -p
顯示所有的資料庫:
show databases;
使用某一個數據庫:
use databasename;
顯示一個數據庫的所有表:
show tables;
退出:
quit;
刪除資料庫和資料表
mysql>drop database 資料庫名;
mysql>drop table 資料表名;
使用者相關:
檢視所有的使用者: SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;新建使用者:
CREATE USER
'dog'
@
'localhost'
IDENTIFIED BY
'123456'
;
為使用者授權:
格式:
grant 許可權 on 資料庫.* to 使用者名稱@登入主機 identified by "密碼";
示例:
grant all privileges on testDB.* to [email protected] identified by '1234';然後需要執行重新整理許可權的命令: flush privileges;
為使用者授予部分許可權: grant select,update on testDB.* to [email protected]
授予一個使用者所有資料庫的某些許可權: grant select,delete,update,create,drop on *.* to [email protected]"%" identified by "1234";
刪除使用者: Delete FROM user Where User='test' and Host='localhost';
然後重新整理許可權; 刪除賬戶及許可權:>drop user 使用者名稱@'%';
>drop user 使用者名稱@ localhost;
修改指定使用者密碼
使用root登入:
mysql -u root -p
執行命令:
update mysql.user set password=password('新密碼') where User="test" and Host="localhost";
重新整理許可權:
flush privileges;