1. 程式人生 > >linux下在mysql資料庫中建立和刪除使用者

linux下在mysql資料庫中建立和刪除使用者

第一步:進入mysql

mysql -uroot msyql -p 回車輸入root使用者的密碼(安裝mysql時自己指定的)

建立一個test使用者,密碼位test,“%“代表聯網中的所有使用者都能用test使用者名稱訪問資料庫(所有資料庫中的所有表);

grant all on *.* to 'test'@'%' identified by 'test';

並將/etc/mysql/mysql.cnf中的bind-address一行註釋

訪問a_db中的所有表,用如下語句實現

grant all on a_db.*  to 'test'@'%' identified by 'test';

限制許可權,限制test使用者只能查詢a_db中的所有表

grant select on a_db.* to 'test'@'%' identified by 'test';

檢視mysql中的所有資料庫使用者

select distinct concat('User: ''',user,'''@''',host,''';') as query from mysql.user;

刪除test使用者

delete from user where User='test' and Host='%';

flush privileges;

刪除資料庫和資料表

drop database 資料庫名;

drop table 資料表名;