爲Mysql數據庫創建只讀賬戶的操作步驟

確認需求

確定目的Mysql服務器 示例:172.16.0.64
確定只讀賬號名稱 示例:創建審計賬號auditor
確定只讀賬號密碼 示例:生產環境至少8爲以上,同時包含大小寫字母和數字,示例DsaF3250
確認數據庫或數據表名 示例:允許訪問整個數據庫bookstore_db
確定訪問Mysql服務器的IP 儘量不要用username@%,允許所有IP訪問會給生產環境帶來風險,示例172.16.0.%表示允許172.16.0.0/24網段的所有IP訪問Mysql

執行步驟

  1. 登錄Mysql服務器
  2. 使用Mysql管理員賬號登錄Mysql命令行
/apps/mysql/bin/mysql -u root -h 172.16.0.64  -p --port=7006
# 按提示輸入管理員密碼
  1. 新增只讀賬號並刷新mysql權限
use mysql;
grant select on bookstore_db.* to auditor@'172.16.0.%' identified by "DsaF3250";
flush privileges;
# 查看mysql中已創建的所有賬號
select host,user,password from user;  # mysql5.6
select host,user,authentication_string from user;  # mysql5.7
  1. 測試賬號能否登錄
/apps/mysql/bin/mysql -u auditor -h 172.16.0.64 -p --port=7006 -A bookstore_db
# 按提示輸入密碼DsaF3250

登錄成功說明創建賬號成功

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章