1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#!/bin/bash
# 新增mysql用户组和用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
# 安装需要的工具
yum -q -y install net-tools libaio numactl perl wget
# 创建目录
mkdir /usr/local/mysql5.7 && cd /usr/local/mysql5.7
# 下载MySQL相关的rpm文件
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.24-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.24-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.24-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.24-1.el7.x86_64.rpm
# 移除已有的mariadb
yum -q -y remove mariadb-*
# 安装MySQL
yum -y install mysql-community-{server,client,common,libs}-*
# 初始化MySQL
mysqld --initialize --user=mysql
chown mysql:mysql /var/lib/mysql -R
mysql_ssl_rsa_setup
# 启动MySQL
systemctl start mysqld
systemctl enable mysqld
echo ""
echo "下面是MySQL的临时密码, 请在登录MySQL后使用如下语句修改MySQL的密码"
grep 'temporary password' /var/log/mysqld.log
echo "修改root密码的SQL:"
echo "ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';"
echo "修改root权限的SQL:"
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';"
echo "刷新权限的SQL:"
echo "FLUSH PRIVILEGES;"
echo ""
mysql -uroot -p
|