gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 17:46:48 25 4
gpt4 key购买 nike

我想在 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

请告诉我如何解决这个问题

最佳答案

在Redhat中,首先创建MySQL的用户帐户。例如用户:mysql密码:blablabla以及默认登录路径:/app/mysql/。完成后以 mysql 用户身份登录并在 .bash_profile 中设置必要的设置,最后安装 MySQL。

希望这对您有帮助。

关于mysql - 使用自定义用户名和密码在 Redhat 上安装 mysql-server 5.7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49751678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com