MySQL的帳號操作
一 查看所有用戶
在mysql的user表中存盤了MySQL的用戶資訊
主要欄位:
- Host表示允許訪問的主機
- User表示用戶名
- authentication_string表示加密后的密碼
desc user; # 查看用戶資訊
二 創建用戶和授權
# root賬戶登錄
mysql -uroot -p
# 常用權限串列:create、alter、drop、insert、update、delete、select 如果分配所有權限,可以使用all privileges
# 訪問主機通常使用:百分號%,表示此賬戶可以使用任何ip的主機登錄訪問此資料庫
# 訪問主機可以設定成 localhost或具體的ip,表示只允許本機或特定主機訪問
grant 權限名稱 on 資料庫 to '用戶名'@'訪問主機' identified by '密碼';
# 查看用戶有哪些權限
show grants for chenjunming@localhost;
# 退出root登錄
quit
三 修改權限
grant 權限名稱 on 資料庫 to 賬戶@'主機' with grant option;
四 修改密碼
update user set authentication_string=password('新密碼') where user='用戶名';
flush privileges; # 重繪權限
五 洗掉賬戶
# 方法一
drop user '用戶名'@'主機';
# 方法二
delete from user where user='用戶名';
flush privileges
六 遠程登錄(危險慎用)
vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 0.0.0.0
service mysql restart # 重啟
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/52446.html
標籤:MySQL
上一篇:MySQL 配置統計資料
下一篇:細說mysql索引
