1、关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
2、关闭SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效
3.下载源码编译安装包
以官方文档安装必备依赖:CMake、make 3.75或更高版本、ANSI C ++编译器、SSL库、Boost C ++库、ncurses相关、bison相关
yum install -y cmake make gcc gcc-c++ openssl openssl-devel ncurses ncurses-devel bison bison-devel wget lrzsz
下载官方的带boost源码包mysql-boost-5.7.30.tar.gz
/usr/local/src/
5.7.30版本
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.30.tar.gz
5.7.24版本
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.24.tar.gz
若下载失败(下载成功此步跳过),可安装rz从本地上传mysql-boost-5.7.30.tar.gz
下载Boost_1_59_0.tar.gz
wget http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
安装boost
tar xf boost_1_59_0.tar.gz
mv boost_1_59_0 /usr/local/
mv boost_1_59_0 boost
4.先检查有没有安装过mysql或mariadb
rpm -qa |grep mysql
rpm -qa |grep mariadb
我有个mariadb-libs-5.5.64-1.el7.x86_64,把它给卸载了
rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64 --nodeps
5.开始安装mysql
[root@localhost src]#groupadd mysql
[root@localhost src]# useradd -g mysql mysql -s /bin/false
[root@localhost src]# mkdir -p /data/server/mysql5.7/db/ 数据库存放目录
[root@localhost src]# mkdir -p /data/server/mysql5.7/binlog/
[root@localhost src]# chown mysql:mysql -R /data/server/mysql5.7/db/
[root@localhost src]# chown mysql:mysql -R /data/server/mysql5.7/binlog/
[root@localhost src]# mkdir -p /usr/local/mysql5.7 安装目录
[root@localhost src]# mkdir -p /var/lib/mysql #sock 存放文件目录
[root@localhost src]# chmod 777 /var/lib/mysql
cd /usr/local/src
tar xf mysql-5.7.30.tar.gz #解压
cd mysql-5.7.30 #进入目录
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.7 \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/data/server/mysql5.7/db \
-DMYSQL_USER=mysql \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORABE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=latin1 \
-DDEFAULT_COLLATION=latin1_swedish_ci \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1 \
-DWITH-SYSTEMD=1 \
-DWITH_BOOST=/usr/local/boost
编译安装
make && make install
6.配置mysql配置文件
vi /etc/my.cnf
[mysqld]
datadir = /data/server/mysql5.7/db
sock= /var/lib/mysql/mysql.sock
innodb_lock_wait_timeout = 500
max_allowed_packet = 16M
innodb_buffer_pool_size = 1G
#lower_case_table_names = 1
max_connections = 1024
user = mysql
server-id = 1
symbolic-links= 0
innodb_file_per_table = 1
event_scheduler= ON
port = 3306
#character_set_server = utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
log-bin=/data/server/mysql5.7/binlog/log-DB.index
expire_logs_days = 7
pid-file=/data/server/mysql5.7/db/mysql.pid
7.进入MySQL安装目录
cd /usr/local/mysql5.7
初始化数据库
./bin/mysqld --user=mysql --initialize-insecure --basedir=/usr/local/mysql5.7/ --datadir=/data/server/mysql5.7/db/
cp /usr/local/mysql5.7/support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动
chmod 755 /etc/init.d/mysqld
chkconfig mysqld on
vi /etc/rc.d/init.d/mysqld #编辑
basedir=/usr/local/mysql5.7
datadir=/data/server/mysql5.7/db
:wq! #保存退出
8.启动数据库
[root@VM7 mysql5.7]# service mysqld start #启动mysql
Starting MySQL.. SUCCESS!
vi /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行
export PATH=$PATH:/usr/local/mysql5.7/bin
:wq! #保存退出
source /etc/profile #使配置立刻生效
下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。
ln -s /usr/local/mysql5.7/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql5.7/include/mysql /usr/include/mysql
mkdir /var/lib/mysql #创建目录
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #添加软链接
service mysqld restart #重启数据库
配置mysql 用户及密码
mysql
grant all on . to 'root'@'localhost' identified by '123456';
flush privileges;