1.创建目录
mkdir -p /server/tools
mkdir /application
mkdir /mysql-data/mysql/data -p
2.建用户与环境变量
useradd -s /sbin/nologin mysql
echo "export PATH=/application/mysql/bin:$PATH" >>/etc/profile
source /etc/profile
3.下载与解压文件
cd /server/tools/
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar
tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar
tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql
4.授权
chown -R mysql.mysql /application/*
chown -R mysql.mysql /mysql-data
5.安装依赖库
yum install ncurses-devel libaio-devel -y
ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5
ln -s /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5
6.准备配置文件
cat >/etc/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/application/mysql
datadir=/mysql-data/mysql/data
socket=/tmp/mysql.sock
server_id=6
port=3306
[mysql]
socket=/tmp/mysql.sock
EOF
7.初始化(无密码)
mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/mysql-data/mysql/data
8.启动数据库
cat >/etc/systemd/system/mysqld.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
EOF
systemctl start mysqld
systemctl enable mysqld
9.设置密码
mysqladmin -uroot password