1 下载安装包
官网下载地址 https://dev.mysql.com/downloads/mysql/5.7.html#downloads
2 添加mysql用户组及mysql用户
groupadd mysql
useradd -M -s /sbin/nologin mysql -g mysql
3 解压二进制文件至安装目录,我这里安装目录为/usr/local/mysql
tar zxf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysql
4 创建mysql数据存放的目录
mkdir -p /data/mysql
5 更改所属的组和用户
chown -R mysql:mysql /usr/local/mysql/
chown -R mysql:mysql /data/mysql/
6 编辑参数文件
vi /etc/my.cnf
[client]
port = 3306
socket = /data/mysql/mysql.sock
[mysqld]
port = 3306
user = mysql
socket = /data/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
#以下设置utf8mb4字符集,可忽略
character-set-server = utf8mb4
init_connect='SET NAMES utf8mb4'
default_storage_engine = innodb
#日志记录路径,需要mysql账户对其有写权限,先touch新建再更改所属组
log-error=/var/log/mysqld.log
7 初始化数据库
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
8 配置启停服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
9 启动mysql服务
service mysqld start
10 设置环境变量
MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
source /etc/profile
PATH=$PATH:/usr/local/mysql/bin >>/etc/profile
11 设置密码
mysql -uroot -p
mysql> SET PASSWORD=PASSWORD('root');
mysql> flush privileges;