如何在centos7系统下编译安装mysql5.7?

如何在centos7系统下编译安装mysql5.7?

一、安装约定

mysql安装路径: /usr/local/mysql

mysql数据库路径: /data/mysql

my配置文件路径: /usr/local/mysql/my.cnf

二、卸载mariadb

# rpm -qa | grep mariadb
# rpm -e --nodeps mariadb-libs-5.5.37-1.el7_0.x86_64 包名是上一条查询得知

三、创建用户组、用户

添加mysql组 groupadd mysql

添加用户 useradd -g mysql mysql -s /bin/false

#下载源码包

在官网如下地址下载最新版

http://dev.mysql.com/downloads/mysql/5.7.html#downloads

http://download.savannah.gnu.org/releases/libunwind/

https://github.com/gperftools/gperftools/releases

# cd /usr/local/src/
# wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz
# wget http://gperftools.googlecode.com/files/gperftools-2.5.tar.gz
# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.x.tar.gz

libunwind安装

# tar zxvf libunwind-1.1.tar.gz
# cd libunwind-1.1
# ./configure
# make
# make install

gperftools安装

# cd ..
# tar zxvf gperftools-2.1.tar.gz
# cd gperftools-2.1
# ./configure
# make
# make install
# echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
# ldconfig

mysql安装

# cd ..
# tar zxvf mysql-5.7.x.tar.gz
# cd mysql-5.7.x

编译前可用如下命令查看编译参数说明

# cmake . -LH | more

如果中间过程有报错,请删除CMakeCache.txt,在重新编译

rm -rf CMakeCache.txt

mysq编译安装

# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
 -DMYSQL_DATADIR=/data/mysql \
 -DSYSCONFDIR=/etc \
 -DEXTRA_CHARSETS=all \
 -DDEFAULT_CHARSET=utf8 \
 -DDEFAULT_COLLATION=utf8_general_ci \
 -DWITH_INNOBASE_STORAGE_ENGINE=1 \
 -DENABLED_LOCAL_INFILE=1 \
 -DMYSQL_UNIX_ADDR=/dev/shm/mysql.sock \
 -DMYSQL_TCP_PORT=3306 \
 -DMYSQL_USER=mysql \
 -DWITH_DEBUG=0 \
 -DDOWNLOAD_BOOST=1 \
 -DWITH_BOOST=/usr/local/boost
# make
# make install
 ```
 
 更改权限
 ```
# chmod 755 /var/lib/mysql
# cd /usr/local/mysql
# chown -R mysql:mysql .

初始化mysql

/usr/local/mysql/bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql --explicit_defaults_for_timestamp=1

创建mysql配置文件

# cp support-files/my-default.cnf /usr/local/mysql/my.cnf

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。