1. 程式人生 > >MySQL建立資料庫與建立使用者以及授權

MySQL建立資料庫與建立使用者以及授權

1、create schema [資料庫名稱] default character set utf8 collate utf8_general_ci;--建立資料庫

  採用create schema和create database建立資料庫的效果一樣。

2、create user '[使用者名稱稱]'@'%' identified by '[使用者密碼]';--建立使用者

  密碼8位以上,包括:大寫字母、小寫字母、數字、特殊字元

  %:匹配所有主機,該地方還可以設定成‘localhost’,代表只能本地訪問,例如root賬戶預設為‘localhost‘

3、grant select,insert,update,delete,create on [資料庫名稱].* to [使用者名稱稱];--使用者授權資料庫

  *代表整個資料庫

4、flush  privileges ;--立即啟用修改

5、revoke all on *.* from tester;--取消使用者所有資料庫(表)的所有許可權

6、delete from mysql.user where user='tester';--刪除使用者

7、drop database [schema名稱|資料庫名稱];--刪除資料庫