1. 下载软件
https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
2. 创建不可登录mysql用户
# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql
3. 安装libaio
# rpm -qa | grep libaio
# yum -y install libaio libaio-devel
4. 解压mysql安装包
# tar xzf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
5. 将源码包剪切到相应目录
# mv mysql-5.7.12-linux-glibc2.5-x86_64 /usr/local/mysql
6. 复制配置文件
# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
7. 修改配置文件
# vim /etc/my.cnf
basedir = /usr/local/mysql/
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
8. 初始化数据库
# cd /usr/local/mysql
# bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
命令参数解释:
--defaults-file :制定MySQL配置文件路径
--initialize :初始化随机密码,注意,初始化的密码是一个过期密码,登录后需要修改密码
--user :指定账户
随机密码:
2017-10-11T16:39:07.365065Z 1 [Note] A temporary password is generated for root@localhost: 9)J>7swK/Ue_
9. 将 mysqld 加入 service 系统服务
# cp support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
10. 启动mysql 服务器
# service mysqld start
11. 配置 mysql 环境变量
# vim /etc/profile
### Mysql
export PATH=$PATH:https:/usr/local/mysql/bin
# source /etc/profile
12. 修改密码
# mysql -u root -p
Enter password: 9)J>7swK/Ue_
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysqlpasswd';
mysql> flush privileges;
mysql> quit
13. 登录mysql
# mysql -uroot -pmysqlpasswd
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2428
Server version: 5.7.12 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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>