环境
- 操作系统: centos7
- mysql : 5.7
创建mysql用户和组 以及相关目录
groupadd mysql
useradd -r -g mysql mysql
mkdir -p /data/mysql/data /data/mysql/log
下载安装包并初始化数据库
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
tar xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/webserver/mysql
cd /usr/local/webserver/mysql
chown -R mysql:mysql .
# basedir放在前面
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/webserver/mysql --datadir=/data/mysql/data
# 修改文件权限
touch /data/mysql/error.log
chown -R root .
chmod -R 755 /data/mysql/.
chown -R mysql:mysql /data/mysql/.
配置my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
server-id = 1
port = 3307
basedir=/usr/local/webserver/mysql
datadir=/data/mysql/data
socket=/data/mysql/mysql.sock
log_error=/data/mysql/log/error.log
配置启动脚本
- 修改启动脚本的basedir和datadir 。
vim support-files/mysql.server
basedir=/usr/local/webserver/mysql
datadir=/usr/local/webserver/mysql/data
chown -R mysql:mysql /data/mysql/.
cp support-files/mysql.server /etc/init.d/mysql
ps -aux | grep mysql
kill 2304
service mysql status
service mysql stop
service mysql stop