mysql 權(quán)限管理


  • 數(shù)據(jù)庫(kù)管理:
# 新建數(shù)據(jù)庫(kù):
create database testdb_01;

# 刪除數(shù)據(jù)庫(kù):
drop database testdb_01;

# 數(shù)據(jù)備份:
# 1、單庫(kù)備份:
mysqldump -uroot -p123456 test01 > /www/xiaozhushe/backup/01.sql;   # 只備份表和數(shù)據(jù),不包含數(shù)據(jù)庫(kù)的創(chuàng)建
# 2、對(duì)多個(gè)庫(kù)進(jìn)行備份:
mysqldump -uroot -p123456 --databases test01 test02 > /www/xiaozhushe/backup/02.sql;
# 3、備份所有庫(kù):
mysqldump -uroot -p123456 --all-databases > /wwww/xiaozhushe/backup/03.sql;
# 4、備份單個(gè)表:
mysqldump -uroot -p123456 test01 t_user > /www/xiaozhushe/backup/04.sql;

# 數(shù)據(jù)恢復(fù):
source /www/xiaozhushe/backup/02.sql;
  • 數(shù)據(jù)表管理:
show create table xxx    # 查看表結(jié)構(gòu)

# 復(fù)制數(shù)據(jù)表
create table 新表 like 舊表;    # 復(fù)制表結(jié)構(gòu)
insert into 新表 select * from 舊表;    # 復(fù)制數(shù)據(jù)
  • 用戶(hù)管理:
創(chuàng)建用戶(hù):
create user 'lisi'@'%' identified by '123456';

修改密碼:
alter user 'lisi'@'%' identified by '123123';

刪除用戶(hù):
drop user 'lisi'@'%'
  • 取消訪(fǎng)問(wèn)ip限制:
use mysql;
update user set host='%' where user='root';
flush privileges;
  • 權(quán)限管理:
# 授權(quán)數(shù)據(jù)操作權(quán)限:
grant select on testdb.* to zhangsan@'%';
grant insert on testdb.* to zhangsan@'%';
grant update on testdb.* to zhangsan@'%';
grant delete on testdb.* to zhangsan@'%';
grant select, insert, update, delete on testdb.* to zhangsan@'%';

# 授權(quán)表結(jié)構(gòu)操作權(quán)限:
grant create on testdb.* to zhangsan@'%';
grant alter on testdb.* to zhangsan@'%';
grant drop   on testdb.* to zhangsan@'%';

# 授權(quán)單個(gè)數(shù)據(jù)庫(kù)管理權(quán)限:
grant all on testdb to zhangsan@'%';

# 授權(quán)所有數(shù)據(jù)庫(kù)管理權(quán)限:
grant all on *.* to zhangsan@'%';

# 查詢(xún)用戶(hù)權(quán)限:
show grants for zhangsan@'%';

# 撤銷(xiāo)用戶(hù)權(quán)限:
revoke all on *.* from zhangsan@'%';
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容