使用自定义用户名和密码在redhat上安装mysql server 5.7

igsr9ssn  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(315)

我想在redhat上安装一个mysql服务器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

请让我知道如何解决这个问题

af7jpaap

af7jpaap1#

在redhat中,首先为mysql创建用户帐户。例如 user:mysql 以及 password:blablabla 和默认登录 path:/app/mysql/ . 完成后,以mysql用户身份登录并在.bash\u profile中设置必要的设置,最后安装mysql。
希望这对你有帮助。

相关问题