我正在尝试通过自动响应来自动化 mysql_secure_installation 脚本。我的代码如下:
echo "& y y abc abc y y y y" | ./usr/bin/mysql_secure_installation
我正在自动化的实际问题如下:
Enter current password for root (enter for none): <enter>
Set root password? [Y/n] y
New password: abc
Re-enter new password: abc
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
但它给了我一个错误“对不起,您不能在此处使用空密码”,但在屏幕上我曾经在第一个问题时按返回键。
最佳答案
我偶然发现了这个问题,但决定通过 Bash 脚本手动运行查询:
#!/bin/bash
# Make sure that NOBODY can access the server without a password
mysql -e "UPDATE mysql.user SET Password = PASSWORD('CHANGEME') WHERE User = 'root'"
# Kill the anonymous users
mysql -e "DROP USER ''@'localhost'"
# Because our hostname varies we'll use some Bash magic here.
mysql -e "DROP USER ''@'$(hostname)'"
# Kill off the demo database
mysql -e "DROP DATABASE test"
# Make our changes take effect
mysql -e "FLUSH PRIVILEGES"
# Any subsequent tries to run queries this way will get access denied because lack of usr/pwd param
关于mysql - 通过 shell 脚本使用 echo 命令自动化 mysql_secure_installation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24270733/