我正在使用Centos 7,并试图编写一个脚本来安装MySQL5.7。我知道如何手动更改根密码,但是如何在脚本中这样写呢?
我已经有了这个:
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum -y localinstall mysql57-community-release-el7-7.noarch.rpm
yum -y install mysql-community-server
service mysqld start下面是我所知道的手动操作:获取临时密码
grep 'temporary' /var/log/mysqld.log然后在提示下输入并输入pass。
mysql -u root -p
Enter Passwword:然后更改pass或运行mysql_secure_installation
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Newhakase-labs123@';
flush privileges;发布于 2018-10-21 04:27:44
我在Google上的CentOS 7.5实例上测试了这些命令。脚本执行完成后,您应该能够使用新密码登录到数据库服务器。
#!/bin/bash
# Description: Set up MySQL Community Release 5.7
# Get the repo RPM and install it.
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum -y install ./mysql57-community-release-el7-7.noarch.rpm
# Install the server and start it
yum -y install mysql-community-server
systemctl start mysqld
# Get the temporary password
temp_password=$(grep password /var/log/mysqld.log | awk '{print $NF}')
# Set up a batch file with the SQL commands
echo "ALTER USER 'root'@'localhost' IDENTIFIED BY 'Newhakase-labs123@'; flush privileges;" > reset_pass.sql
# Log in to the server with the temporary password, and pass the SQL file to it.
mysql -u root --password="$temp_password" --connect-expired-password < reset_pass.sqlhttps://unix.stackexchange.com/questions/476802
复制相似问题