- 連接數據庫
mysql -u用戶名 -p密碼 -h主機地址
- 創建數據庫
//創建一個名為sql_test的數據庫,并指定編碼格式為utf8
create database if not exists sql_test default character set utf8 collate utf8_general_ci;
-
創建用戶并授權
模式:
grant 權限 數據庫名.表名 to '用戶名'@'指定連接' identified by '用戶密碼' with grant option;
數據庫的權限列表
- [ 查] select
- [插] insert
- [更新]update
- [刪除]delete
- [創建]create
- [清空]drop
ex:
grant select ON tablename.* TO 'username'@'localhost' IDENTIFIED BY 'password';
//創建一個用戶名為userName,密碼為password的用戶,并獲取所有權限且支持遠程連接數據庫
grant all privileges *.* to 'userName'@'%' identified by 'password' with grant option;
- 刷新MySQL的系統權限相關表
flush privileges;