美文网首页
CentOS安装MySQL5.7(编译安装)

CentOS安装MySQL5.7(编译安装)

作者: 王哈哈就很棒 | 来源:发表于2020-05-26 13:18 被阅读0次

安装依赖

yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake make wget vim

一键换yum源(可选)

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak && wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && yum makecache

or

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache

1.下载软件包

wget -P /usr/local/src https://develop1024.gitee.io/lamp/boost_1_59_0.tar.gz
wget -P /usr/local/src http://develop1024.gitee.io/lamp/mysql-5.7.17.tar.gz

2.解压

tar -xvf boost_1_59_0.tar.gz
tar -xvf mysql-5.7.17.tar.gz
mv boost_1_59_0 /usr/local/boost

3.创建mysql运行用户

# 创建用户mysql,不创建家目录,不允许登陆系统
useradd -M -s /sbin/nologin mysql

4.配置

cd mysql-5.7.17

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost \
-DWITH_SYSTEMD=1

如遇错误,删除 CMakeCache.txt 再重新CMAKE,否则错误依旧
rm -fvr CMakeCache.txt

5.编译安装

make
make install

6.修改数据库目录权限

chown -R mysql:mysql /usr/local/mysql/

7.修改配置文件

vim /etc/my.cnf

[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

修改配置文件的权限

chown mysql:mysql /etc/my.cnf

8.设置环境变量

vim ~/.bashrc

export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib

source ~/.bashrc

9.初始化数据库

cd /usr/local/mysql

bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

10.添加系统服务

cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload    //刷新识别mysqld.service服务
systemctl enable mysqld    //加入系统自启动
systemctl start mysqld     //启动服务

相关文章

网友评论

      本文标题:CentOS安装MySQL5.7(编译安装)

      本文链接:https://www.haomeiwen.com/subject/iqwmahtx.html