Shell腳本中執行sql語句操作

#!/bin/bash
#等號左右不能有空格
install_path=
mysql_root_user="root"
mysql_root_password=
mysql_host=

# 創建用戶
function create_mysql_user(){
    mysql -u${mysql_root_user} -p${mysql_root_password} -e "GRANT REPLICATION CLIENT, PROCESS ON *.* TO ${mysql_exporter_user}@'${mysql_host}' identified by '${mysql_exporter_password}';
    GRANT SELECT ON performance_schema.* TO '${mysql_exporter_user}'@'${mysql_host}';" 2> /dev/null
}

create_mysql_user

參考:https://zhidao.baidu.com/question/878213827483738492.html

  1. 查看MySQL的所有用戶命令
    SELECT User FROM mysql.user
  2. 使用2> /dev/null的原因是有時連接時出現warning:時可以忽略
發佈了59 篇原創文章 · 獲贊 15 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章