首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Centos使用bash脚本安装MYSQL 5.7

问用Centos使用bash脚本安装MYSQL 5.7
EN

Unix & Linux用户
提问于 2018-10-21 01:46:44
回答 1查看 6.1K关注 0票数 2

我正在使用Centos 7,并试图编写一个脚本来安装MySQL5.7。我知道如何手动更改根密码,但是如何在脚本中这样写呢?

我已经有了这个:

代码语言:javascript
复制
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

下面是我所知道的手动操作:获取临时密码

代码语言:javascript
复制
grep 'temporary' /var/log/mysqld.log

然后在提示下输入并输入pass。

代码语言:javascript
复制
mysql -u root -p
Enter Passwword:

然后更改pass或运行mysql_secure_installation

代码语言:javascript
复制
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Newhakase-labs123@';
flush privileges;
EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2018-10-21 04:27:44

我在Google上的CentOS 7.5实例上测试了这些命令。脚本执行完成后,您应该能够使用新密码登录到数据库服务器。

代码语言:javascript
复制
#!/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.sql
票数 4
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/476802

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档