我想在Redhat上安装一个mysql-server 5.7,在shell脚本中使用自定义用户名和密码。
对于Ubuntu,我看到如下的3行命令,我想以简单的方式为Redhat采用相同的方法
echo "mysql-server mysql-server/root_password password $MYSQL_ROOT_PASSWORD" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD" | debconf-set-selections
apt -y install mysql-server
更新1: -
newPassword=root
echo "Stopping mysql..."
systemctl stop mysqld
echo "Setting the mySQL environment option.."
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
echo "Starting mysql ignoring password verification.."
systemctl start mysqld
echo "Updating the root user password with your provided password"
echo "UPDATE mysql.user SET authentication_string = PASSWORD('$newPassword') WHERE User = 'root' AND Host = 'localhost';" | mysql -u root
echo "FLUSH PRIVILEGES;" | mysql -u root
echo "Stopping mysql.."
systemctl stop mysqld
echo "Un setting the mySQL environment option so it starts normally next time.."
systemctl unset-environment MYSQLD_OPTS
echo "Start mysql normally.."
systemctl start mysqld
我试过上面的答案。它运作良好。但是在用更新的密码登录到mysql之后。我看到以下错误
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.21
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> exit
请让我知道如何解决这个问题
答案 0 :(得分:0)
在Redhat中,首先为MySQL创建用户帐户。例如user:mysql
和password:blablabla
以及默认登录path:/app/mysql/
。一旦以mysql用户身份登录并在.bash_profile中设置必要的设置,最后安装MySQL。
希望这会对你有所帮助。