1.安装前准备
#安装编译源码所需的工具和库
yum install gcc gcc-c++ ncurses-devel perl
yum groupinstall -y "Development tools" "Desktop Platform Development" "Server Platform Development"
yum -y install cmake
2.删除系统自带的MySQL
rpm -qa | grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
3.创建数据库目录、mysql用户,并修改数据目录的属主
mkdir -pv /mydata/data
useradd -s /sbin/nologin mysql
chown -R mysql.mysql /mydata/data/
4.下载tar包解压
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.37.tar.gz
tar -xf mysql-5.6.37.tar.gz -C /usr/local/
5.设置编译参数,编译,安装
cd /usr/local/mysql-5.6.37/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DINSTALL_DATADIR=/mydata/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
make
make install
6.初始化数据库
cd /usr/local/mysql/scripts/
./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/mydata/data/
7.复制MySQL服务启动脚本
cd /usr/local/mysql/support-files/
cp mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
8.设置开机启动
chkconfig --add mysqld
chkconfig --list mysqld
#mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
9.优化MySQL命令的执行路径
vi /etc/profile
在/etc/profile文件末尾添加如下两行
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
添加完成后退出编辑,执行如下命令使配置生效
source /etc/profile
10.复制MySQL配置文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf
在my.cnf文件中增加如下配置:
innodb_file_per_table = 1
datadir = /mydata/data
port = 3306
user = mysql
server_id = 1
socket = /tmp/mysql.sock
11.启动MySQL服务
service mysqld restart
netstat -antp | grep mysql
#tcp 0 0 :::3306 :::* LISTEN 34016/mysqld