先以root用戶登陸mysql:mysql
C:\Users\XXX>mysql -u root -pspring
輸入密碼後登陸,接下來操做以下:sql
一、建立數據庫數據庫
語法:create schema [數據庫名稱] default character set utf8 collate utf8_general_ci;ide
採用create schema和create database建立數據庫的效果同樣。this
示例:create schema spring_boot_demo default character set utf8 collate utf8_general_ci;.net
二、建立用戶server
語法:create user '[用戶名稱]'@'%' identified by '[用戶密碼]';blog
密碼8位以上,包括:大寫字母、小寫字母、數字、特殊字符ip
%:匹配全部主機,該地方還能夠設置成‘localhost’,表明只能本地訪問,例如root帳戶默認爲‘localhost‘
示例:create user 'szh'@'localhost' identified by '123456';
三、用戶受權數據庫
grant select,insert,update,delete,create on [數據庫名稱].* to [用戶名稱]@'%';
*表明整個數據庫
示例:grant select,insert,update,delete,create on spring_boot_demo.* to szh@'localhost';
四、當即啓用修改
flush privileges ;
五、取消用戶szh全部數據庫(表)的全部權限
revoke all on *.* from szh;
六、刪除用戶szh
delete from mysql.user where user='szh';
七、刪除數據庫
drop database [schema名稱|數據庫名稱];
PS : 在操做過程當中若是遇到錯誤
"The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement"
則先進行一下刷新操做:
mysql> flush privileges; --這樣就能夠接着操做了