Mariadb常用管理操作
一 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@'%';
說完基礎的資料庫許可權和操作,下一次所說跟表相關的內容