MySQL57源码编译安装

MySQL57源码编译安装

软件准备

下载mysql安装包(注意选择source code)

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20.tar.gz

下载boost库

 wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

安装相关依赖

yum install -y git  cmake   gcc   gcc-c++  bison   ncurses   ncurses-devel bison-devel  libaio-devel

编译安装

创建工作目录和数据目录(我的数据盘是挂在/opt下的)

mkdir -p /opt/mysql && mkdir -p /opt/mysql/data

创建用户

groupadd -r mysql
useradd -r -g mysql -s /sbin/nologin mysql

授权用户

chown -R mysql:mysql /opt/mysql
chown -R mysql:mysql /opt/src/boost_1_59_0

开始编译生成makefile

	cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \   
-DMYSQL_DATADIR=/usr/local/mysql/data \  
-DWITH_BOOST=/usr/local/boost_1_59_0 \ # 必须  
-DSYSCONFDIR=/etc \ # mysql配置文件my.cnf所在路径`/etc/my.cnf`    
-DENABLED_LOCAL_INFILE=1 \  
-DEXTRA_CHARSETS=all  

正常命令

cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql \
-DMYSQL_DATADIR=/opt/mysql \
-DWITH_BOOST=/opt/src/boost_1_59_0 \
-DSYSCONFDIR=/opt/mysql \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all

多线程编译

make -j `grep processor /proc/cpuinfo | wc -l`

安装

make install

MySQL初始化

mkdir /var/log/mariadb
chown -R mysql:mysql /var/log/mariadb

bin/mysqld --initialize --user=mysql

添加service文件

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

重新加载unit单元

systemctl daemon-reload

修改密码

SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
flush privileges;

你可能感兴趣的:(MySQL)