命令行下創建MySQL數據庫與創建用戶以及授權


先以root用戶登錄mysql:

C:\Users\XXX>mysql -u root -p

輸入密碼后登錄,接下來操作如下:

1、創建數據庫

語法:create schema [數據庫名稱] default character set utf8 collate utf8_general_ci;

  采用create schema和create database創建數據庫的效果一樣。

示例:create schema spring_boot_demo default character set utf8 collate utf8_general_ci;

2、創建用戶

語法:create user '[用戶名稱]'@'%' identified by '[用戶密碼]';

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

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

示例:create user 'szh'@'localhost' identified by '123456';

3、用戶授權數據庫

grant select,insert,update,delete,create on [數據庫名稱].* to [用戶名稱]@'%';

  *代表整個數據庫

示例:grant select,insert,update,delete,create on spring_boot_demo.* to szh@'localhost';

4、立即啟用修改

flush  privileges ;

 

5、取消用戶szh所有數據庫(表)的所有權限

revoke all on *.* from szh;

6、刪除用戶szh

delete from mysql.user where user='szh';

7、刪除數據庫

drop database [schema名稱|數據庫名稱];

 

PS : 在操作過程中如果遇到錯誤

"The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement"

則先進行一下刷新操作:

mysql> flush privileges; --這樣就可以接着操作了


---------------------
作者:憂國一小民
來源:CSDN
原文:https://blog.csdn.net/sunzhenhua0608/article/details/80382960
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM