cd /usr/local/
tar -zxvf mysql-5.7.27-el7-x86_64.tar.gzmv mysql-5.7.27-el7-x86_64 mysql
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
yum install -y libaio
进入 MySQL 目录,并初始化数据库:
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
记录下密码
创建 MySQL 配置文件 my.cnf,通常放置在 /etc/ 目录下:
vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /tmp/mysql.sock
user = mysql
symbolic-links = 0[mysqld_safe]
log-error = /usr/local/mysql/data/mysql.err
pid-file = /usr/local/mysql/data/mysql.pid[client]
port = 3306
socket = /tmp/mysql.sock
设置系统环境变量
为了方便使用 MySQL 命令,将 MySQL 的 bin 目录加入到系统的环境变量中:
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
source /etc/profile
启动 MySQL
使用 mysqld_safe 启动 MySQL:
/usr/local/mysql/bin/mysqld_safe --user=mysql &