資料庫基礎權限管理,
一 Mariadb常用管理操作
純幹貨,沒有一點廢話,全是使用頻率最高和常用的操作,運維必不可少的基礎資料。
1.1 建立資料庫
>create database <db_name>; #快速建立資料庫
----------------------------------------------
>create database <db_name> default character set utf8 collate utf8_general_ci; #建立資料庫并設定字元集為utf-8
>show create database <db_name>; #檢視資料庫字元集
1 修改資料庫的字元集
alter database <db_name> character set utf8;
2 修改表的字元集
alter table <table_name> character set utf8;
3 修改字段的字元集
alter table <table_name> change <Field> <Field1> <Field2> character set utf8; #一般不會使用
1.2 删除資料庫
>drop database <db_name>; #删除資料庫
1.3 使用資料庫
>use <db_name>; #使用資料庫
>select database(); #檢視目前連接配接的資料庫
1.4 建立使用者
建立登陸資料庫的使用者,以及登陸的IP限制等
>create user 'test01'@'localhost' identified by 'password'; #隻是建立一個使用者,沒有任何浏覽資料庫的權限
----------------------------------------------------------
>grant all on test_db1.* to 'test02'@'localhost' identified by '123456'; #建立一個使用者'test02',并授權他可以對'test_db1'進行查詢,更新,更改,删除操作,
#'localhost'指的是隻能在本機才可以登陸
select user from mysql.user\G #檢視Mysql内使用者,從'mysql庫的user表'裡查詢'user'字段
select user,host from mysql.user\G
1.5 删除使用者
drop user 'test01'@localhost
二 Mariadb資料庫的權限管理
2.1 使用者連接配接資料庫權限
1 隻允許來自于本地連接配接資料庫
grant all on test_db1.* to 'test02'@'localhost' identified by '123456'; #'localhost'代表隻允許本地登陸
---------------------------------------------------------------
2 允許區域網路本網段連接配接資料庫
grant all on test_db1.* to 'test02'@'192.168.1.%' identified by '123456'; #'192.168.1.%'允許192.168.1.0網段主機連接配接
---------------------------------------------------------------
3 允許任意位址連接配接資料庫
grant all on test_db1.* to 'test02'@'%' identified by '123456'; #'%'表示允許任意位址連接配接資料庫
2.2 使用者資料庫庫權限
#授權使用者在test_db1資料中擁有,查詢,更新,插入,删除權限
> grant select,update,insert,delete on test_db1.* to 'test02'@'%' identified by '123456';
- select,查詢權限
- update,更新權限
- insert,插入權限
- delete,删除權限
2.3 使用者權限回收
#把'test02'賬号的,插入和查詢權限取消
>revoke insert,select on test_db1.* from test02@'%';
說完基礎的資料庫權限和操作,下一次所說跟表相關的内容