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 mysqluseradd -g mysql mysqlpasswd mysql
3.创建安装目录、数据目录、配置目录等
mkdir -p /usr/local/mysql/mkdir -p /usr/local/mysql/datamkdir -p /usr/local/mysql/etcmkdir -p /usr/local/mysql/logchown -R mysql:mysql /usr/local/mysql/
4.安装依赖包
yum install libaio numactl
5.安装mysql
su - mysqlcd /usr/local/src/tar -xzvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gzmv /usr/local/src/mysql-5.7.23-linux-glibc2.12-x86_64/* /usr/local/mysql/
6.创建my.cnf配置文件
cat > /usr/local/mysql/etc/my.cnf << EOF[client]port = 3306socket=/usr/local/mysql/mysql.sock[mysqld]character_set_server=utf8init_connect=‘SET NAMES utf8‘basedir=/usr/local/mysqldatadir=/usr/local/mysql/datasocket=/usr/local/mysql/mysql.socklog-error=/usr/local/mysql/log/mysqld.logpid-file=/usr/local/mysql/data/mysqld.pidlower_case_table_names = 1 #不区分大小写sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTIONmax_connections=5000default-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/mysqldchkconfig --add mysqldchkconfig --listsystemctl start mysqld
9.登录数据库并修改密码
[mysql@mysql log]$ mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.23Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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> SET PASSWORD = PASSWORD(‘abc123‘);Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> UPDATE `mysql`.`user` SET `Host` = ‘%‘, `User` = ‘root‘ WHERE (`Host` = ‘localhost‘) AND (`User` = ‘root‘);Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> quitBye
1.下载二进制文件