【发布时间】:2020-08-29 15:21:15
【问题描述】:
我正在尝试创建一个 shell 脚本来自动化安装 PHP、MySQL 和 Nginx 的过程。
到目前为止,一切正常。但是,我无法将其身份验证方法从auth_socket 切换到mysql_native_password。
MYSQLPASS=$(openssl rand -base64 32)
sudo apt-get install -y expect
sudo apt-get install -y mysql-server
SECURE_MYSQL=$(expect -c "
set timeout 10
spawn mysql_secure_installation
expect \"Press y|Y for Yes, any other key for No: \"
send \"n\r\"
expect \"New password: \"
send \"$MYSQLPASS\r\"
expect \"Re-enter new password: \"
send \"$MYSQLPASS\r\"
expect \"Remove anonymous users? (Press y|Y for Yes, any other key for No) : \"
send \"y\r\"
expect \"Disallow root login remotely? (Press y|Y for Yes, any other key for No) : \"
send \"y\r\"
expect \"Remove test database and access to it? (Press y|Y for Yes, any other key for No) : \"
send \"y\r\"
expect \"Reload privilege tables now? (Press y|Y for Yes, any other key for No) : \"
send \"y\r\"
expect eof
")
我必须在终端上手动完成。
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<password>';
FLUSH PRIVILEGES;
exit
【问题讨论】:
-
你在用 var
SECURE_MYSQL做什么?如果您没有真正使用它,请放弃var=$() stuff, and stop escaping your"` 等字符:-)!祝你好运!