Centos7.3编译安装MySQL 5.7.17
Centos7.3安装的是minimal最小化版本,首先安装基础必需的软件包:
yum install gcc gcc-c++ gcc-g77 make autoconf automake ncurses ncurses-devel openssl openssl-devel cmake -y
yum install net-tools unzip vim lrzsz wget sysstat -y 此为常用工具,可以不安装
yum update -y
下载MySQL5.7.17安装包,安装包都放在/soft目录下:
mkdir /soft
cd /soft
wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17.tar.gz
添加mysql运行账号及数据保存目录
groupadd mysql
useradd -g mysql mysql -s /bin/false
mkdir -p /data/mysql/db
mkdir -p /data/mysql/binlog
touch /data/mysql/error.log
chown -R mysql:mysql /data/mysql/
如果是5.6及以下版本不用安装boost,直接cmake编译即可:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3307 \
-DSYSCONFDIR=/usr/local/mysql \
-DINSTALL_SHAREDIR=share \
-DWITH_DEBUG=0 \
-DWITH_SSL=system \
-DWITH-mysqld-ldflags=-all-static \
-DWITH-client-ldflags=-all-static \
-DWITH_EMBEDDED_SERVER=OFF
如果是5.7及以上版本,需要先编译boost,如果下载的是自带boost的mysql安装包也不用单独编译boost
tar xvf boost_1_59_0.tar.gz
cd boost_1_59_0
./bootstrap.sh
./b2 install
解压编译安装:
tar xvf mysql-5.7.17.tar.gz
cd mysql-5.7.17
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DSYSCONFDIR=/etc \
-DINSTALL_SHAREDIR=share \
-DWITH_DEBUG=0 \
-DWITH-mysqld-ldflags=-all-static \
-DWITH-client-ldflags=-all-static \
-DWITH_EMBEDDED_SERVER=OFF \
-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/soft/boost_1_59_0
make
make install
以下为mysql-boost-5.7.xx.tar.gz版本编译参数:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3307 \
-DSYSCONFDIR=/usr/local/mysql \
-DINSTALL_SHAREDIR=share \
-DWITH_DEBUG=0 \
-DWITH_SSL=system \
-DWITH-mysqld-ldflags=-all-static \
-DWITH-client-ldflags=-all-static \
-DWITH_EMBEDDED_SERVER=OFF \
-DWITH_BOOST=boost
make
make install
经过漫长的等待,根据机器具体配置时间长短略有区别,安装完成以后开始配置:
cp /soft/mysql-5.7.17/support-files/my-default.cnf /usr/local/mysql/my.cnf
拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接删除即可)
vim /usr/local/mysql/my.cnf #编辑配置文件,在 [mysqld] 部分增加:
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
basedir = /usr/local/mysql
datadir = /data/mysql/db
port = 3306
server_id = 1
socket = /data/mysql/mysql.sock
以下为client和mysql部分:
[mysql]
default-character-set = utf8mb4
[client]
default-character-set = utf8mb4
socket = /data/mysql/mysql.sock
修改完以后wq保存退出,开始初始化、生成mysql系统用户表:
/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/db
如果是5.6及以下版本,使用mysql_install_d初始化、生成系统用户表:
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/usr/local/mysql/my.cnf --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/db
写入系统服务,赋权、并开机启动
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
chmod +x /etc/rc.d/init.d/mysql
编辑vim /etc/rc.d/init.d/mysql文件,设置
basedir=/usr/local/mysql
datadir=/data/mysql/db
数据和安装路径
设置开机启动 systemctl enable mysql
启动MySQL服务 systemctl start mysql
加入系统环境变量和软连接:
vi /etc/profile
加入:export PATH=$PATH:/usr/local/mysql/bin
重新加载peofile
source /etc/profile
建立软连接
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
设置mysql密码及安全参数
mysql_secure_installation
根据系统提示,直接设置即可;
设置完毕以后重启下MySQL服务
systemctl restart mysql
可根据系统应用具体场景优化下/etc/my.cnf,至此安装完毕:
Tag标签:「mysql 安装 编译」更新时间:「2021-11-04 13:00:30」阅读次数:「794」