1.下载二进制文件
cd /usr/local/src/
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
2.创建MySQL组和用户
groupadd mysql
useradd -g mysql mysql
passwd mysql
3.创建安装目录、数据目录、配置目录等
mkdir -p /usr/local/mysql/
mkdir -p /usr/local/mysql/data
mkdir -p /usr/local/mysql/etc
mkdir -p /usr/local/mysql/log chown -R mysql:mysql /usr/local/mysql/
4.安装依赖包
yum install libaio numactl
5.安装mysql
su - mysql
cd /usr/local/src/
tar -xzvf mysql-5.7.-linux-glibc2.-x86_64.tar.gz
mv /usr/local/src/mysql-5.7.-linux-glibc2.-x86_64/* /usr/local/mysql/
6.创建my.cnf配置文件
cat > /usr/local/mysql/etc/my.cnf << EOF
[client]
port =
socket=/usr/local/mysql/mysql.sock
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
log-error=/usr/local/mysql/log/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
lower_case_table_names = #不区分大小写
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=
default-time_zone = '+8:00'
EOF
7.初始化mysql
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
grep 'temporary password' mysqld.log #记录默认密码
8.设置开机启动
su - root
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list
systemctl start mysqld
9.登录数据库并修改密码
[mysql@mysql log]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7. Copyright (c) , , 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 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> SET PASSWORD = PASSWORD('abc123');
Query OK, rows affected, warning (0.01 sec)
mysql> UPDATE `mysql`.`user` SET `Host` = '%', `User` = 'root' WHERE (`Host` = 'localhost') AND (`User` = 'root');
Query OK, row affected (0.00 sec)
Rows matched: Changed: Warnings: mysql> flush privileges;
Query OK, rows affected (0.00 sec) mysql> quit
Bye
1.下载二进制文件