mysql8.0創建數據庫,用戶的增刪改查,用戶分配權限,表空間分配


一、創建數據庫

--創建名稱為“testdb”數據庫,並設定編碼集為utf8
CREATE DATABASE IF NOT EXISTS testdb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

二、添加用戶

--創建了一個名為:test 密碼為:1234 的用戶
create user 'test'@'localhost' identified by '1234';

注意:
此處的"localhost",是指該用戶只能在本地登錄,不能在另外一台機器上遠程登錄。如果想遠程登錄的話,將"localhost"改為"%",表示在任何一台電腦上都可以登錄。也可以指定某台機器可以遠程登錄。

三、刪除用戶

--刪除用戶“test”
drop user test@localhost ;
--若創建的用戶允許任何電腦登陸,刪除用戶如下
drop user test@'%'

四、查詢用戶

--查詢用戶
select user,host from mysql.user;

五、修改用戶密碼

--方法1,密碼實時更新;修改用戶“test”的密碼為“1122”
set password for test =password('1122');
--方法2,需要刷新;修改用戶“test”的密碼為“1234”
update  mysql.user set  password=password('1234')  where user='test'
--刷新
flush privileges;

--上面兩種方法是MYSQL5.7以前使用,MYSQL5.7以后使用下面這個方法
alter user 'test'@'localhost' identified by '1122';

六、用戶分配權限

--授予用戶test通過外網IP對數據庫“testdb”的全部權限
grant all privileges on 'testdb'.* to 'test'@'localhost' identified by '1234';  
--刷新權限
flush privileges; 
--授予用戶“test”通過外網IP對於該數據庫“testdb”中表的創建、修改、刪除權限,以及表數據的增刪查改權限
grant create,alter,drop,select,insert,update,delete on testdb.* to test@'ocalhost';

--上面是MYSQL5.7以前使用的語句,MYSQL5.7以后使用會報錯
--賦予用戶test通過外網IP對數據庫“testdb”的全部權限 grant all privileges on testdb.* to 'test'@'localhost'; --刷新權限 flush privileges; --授予用戶“test”通過外網IP對於該數據庫“testdb”中表的創建、修改、刪除權限,以及表數據的增刪查改權限 grant create,alter,drop,select,insert,update,delete on testdb.* to 'test'@'localhost'; --消除全部權限 revoke all privileges on testdb.* from 'test'@'localhost'; --消除當個權限 revoke select on testdb.* from 'test'@'localhost';

七、查看用戶權限

--查看用戶“test”
show grants for test;

八、表空間的分配

創建表空間

語法:create tablespace tablespacename datafile 'd:\data.dbf' size xxxm;

tablespacename:表空間的名字

d:\data.dbf':表空間的存儲位置

xxx表空間的大小,m單位為兆(M)

將空間分配給用戶

語法:alert user test default tablespace tablespacename;

將名字為tablespacename的表空間分配給test


免責聲明!

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



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