1.查看系统版本
cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
2.下载mysql二进制安装包
wget http://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz
3.解压安装包
tar -xvf mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz
4.安装依赖的lib包
安装需要的包即可:libstdc++.so.6和libaio.so.1和libncurses.so.5
yum install libaio* libncur* libstd* ncurses*
5.移动到/usr/local/mysql
mv mysql-5.6.31-linux-glibc2.5-x86_64 /usr/local/mysql
6.配置用户,目录
mkdir -p /opt/mysql/data
mkdir -p /opt/mysql/sock
mkdir -p /opt/mysql/binlog
mkdir -p /opt/mysql/slowlog
mkdir -p /opt/mysql/pid
mkdir -p /opt/mysql/errlog
groupadd mysql
useradd -g mysql mysql
cd /usr/local/
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /opt/mysql
7.配置my.cnf
vi /etc/my.cnf
[client]
# CLIENT #
port = 3306
socket = /opt/mysql/sock/mysql.sock
[mysqld]
# GENERAL #
port = 3306
user = mysql
basedir = /usr/local/mysql
socket = /opt/mysql/sock/mysql.sock
pid-file = /opt/mysql/pid/mysql.pid
# DATA STORAGE #
datadir = /opt/mysql/data
# BINARY LOGGING #
log-bin = /opt/mysql/binlog/mysql-bin
expire-logs-days = 14
sync-binlog = 1
log-slave-updates
# ERROR LOG #
log-error = /opt/mysql/errlog/mysql-error.log
log-queries-not-using-indexes = 1
#开启慢日志
slow-query-log = 1
slow-query-log-file = /opt/mysql/slowlog/mysql-slow.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
8.初始化数据库
cd /usr/local/mysql/scripts
./mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql
注:也可以选择先初始化数据库,再配置my.cnf
cd /usr/local/mysql/scripts
./mysql_install_db --basedir=/usr/local/mysql --datadir=/opt/mysql/data --user=mysql
9.启停数据库
启动mysql
/usr/local/mysql/support-files/mysql.server start
关闭mysql
killall mysqld 或者
/usr/local/mysql/support-files/mysql.server stop