一、安装依赖
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
二、下载源码包
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.24.tar.gz
解压,进入到目录
三、编译安装
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/usr/local/mysql/etc -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_EMBEDDED_SERVER=OFF -DWITH_SYSTEMD=1
make -j 4
make install
四、配置
在/usr/local/mysql目录下创建 data,var,etc目录
在/usr/local/mysql/var 下创建 run,log目录
添加mysql用户和用户组
groupadd mysql
useradd -g mysql mysql
更改文件目录归属:
chown -R mysql: /usr/local/mysql
编辑配置文件:
vim /usr/local/mysql/etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log_error=/usr/local/mysql/var/log/mysql.log
server-id=1
explicit_defaults_for_timestamp=true
配置系统服务
vim /usr/lib/systemd/system/mysqld.service
# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# systemd service file for MySQL forking server
#
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/usr/local/mysql/var/run/mysqld.pid
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Needed to create system tables
ExecStartPre=/usr/local/mysql/bin/mysqld_pre_systemd
# Start main service
ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/var/run/mysqld.pid $MYSQLD_OPTS
# Reload main service
ExecReload=/bin/kill -HUP $MAINPID
# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql
# Sets open_files_limit
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
添加环境变量
vim /etc/profile
加入:export PATH="/usr/local/mysql/bin:$PATH"
保存
source /etc/profile
五、初始化数据库
配置:
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
启动:
systemctl start mysqld
配置安全向导:
mysql_secure_installation
最后测试mysql
---------------------
作者:淹死的鱼0719
来源:CSDN
原文:https://blog.csdn.net/c571121319/article/details/85132887