在bash脚本中自动安装mysql-server后无法连接到mysql

时间:2015-06-18 12:05:09

标签: mysql linux bash unix

生成随机字符串:

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)

1 个答案:

答案 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"