生成随机字符串:
passdb="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-2};)"
将 passdb 提供给debconf,即为mysql用户设置随机密码:
debconf-set-selections <<< 'mysql-server mysql-server/root_password password $passdb'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password $passdb'
apt-get -y install mysql-server
它已成功安装,但是在从我的bash脚本触发此查询后出现错误:
查询:
mysql --user=root --password=$passdb --execute="CREATE DATABASE IF NOT EXISTS \`$DOMAIN_NM$CONCAT\`; grant all on \`$DOMAIN_NM$CONCAT\`.* to 'wordpressuser'@'localhost' identified by '$OUTPUT1'; FLUSH PRIVILEGES;"
ERROR 1045(28000):用户'root'@'localhost'拒绝访问(使用密码:YES)
答案 0 :(得分:0)
我认为Álvaro对引号的正确性,尝试类似
debconf-set-selections <<< "mysql-server mysql-server/root_password password $passdb"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $passdb"