由于一些奇怪的原因,我找不到一种方法来使runuser命令工作。我知道用sudo -u mysql mysql -e "$DB_SETUP
可以实现这一点,但由于我想在一个已经用sudo
运行的脚本中完成这一点,我发现这不是很好。
这就是我要做的:
DB_SETUP="CREATE USER IF NOT EXISTS $DB_USER@$BASEURL IDENTIFIED BY '$DB_PASSWORD';CREATE DATABASE IF NOT EXISTS $DB_NAME;GRANT ALL PRIVILEGES ON $DB_NAME.* TO $DB_USER@$BASEURL IDENTIFIED BY '$DB_PASSWORD';FLUSH PRIVILEGES;"
sudo runuser -u mysql "mysql -e \"$DB_SETUP\"" # does not work
它给我这个错误:
runuser: failed to execute mysql -e "CREATE USER IF NOT EXISTS db_user@baseurl IDENTIFIED BY 'db_password';CREATE DATABASE IF NOT EXISTS db_name;GRANT ALL PRIVILEGES ON db_name.* TO db_user@baseurl IDENTIFIED BY 'password';": No such file or directory
1条答案
按热度按时间s4chpxco1#
正如上面所评论的,我得到了它的工作:
sudo runuser -u mysql mysql <<< $DB_SETUP
不要使用引号!