MySQL 5.7.24

MySQL 5.7.24

八月 08, 2019

MySQL 5.7.24

目录

[隐藏]

  • [1添加mysql用户]
  • [2安装依赖]
  • [3把系统默认的my.cnf改名,防止冲突]
  • [4编译MySQL]
  • [5默认客户端配置]
  • [6默认配置]
  • [7初始化数据库]
  • [8systemd启动脚本]
  • [9修改连接用户]

添加mysql用户

1
2
groupadd mysql
useradd -gmysql -s /sbin/nologin -M mysql

安装依赖

1
yum install -y gcc gcc-c++ ncurses ncurses-devel cmake

把系统默认的my.cnf改名,防止冲突

1
mv /etc/my.cnf /etc/my.cnf.bak

编译MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.24.tar.gz
tar -xzf mysql-boost-5.7.24.tar.gz
cd mysql-5.7.24/
cmake . \
-DCMAKE_INSTALL_PREFIX=/data/soft/mysql \
-DMYSQL_DATADIR=/data/db/mysql \
-DWITH_BOOST=boost \
-DSYSCONFDIR=/data/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1

make -j4
make install

默认客户端配置

1
2
3
4
5
6
7
8
cat > /data/etc/my.cnf << EOF
[mysql]
default-character-set=utf8
host = 127.0.0.1
socket=/tmp/mysql.sock
EOF

echo 'export PATH=$PATH:/data/soft/mysql/bin' >> /etc/bashrc

默认配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mkdir -p /data/db/mysql/binlog
chown mysql.mysql /data/db/mysql/binlog

cat > /data/db/mysql/my.cnf << EOF
[mysqld]
bind-address = 0.0.0.0
socket=/tmp/mysql.sock
basedir=/data/soft/mysql
datadir=/data/db/mysql/data
log-bin=/data/db/mysql/binlog/binlog
server-id=1
skip-name-resolve
[mysql]
socket=/tmp/mysql.sock
EOF

初始化数据库

1
/data/soft/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/soft/mysql --datadir=/data/db/mysql/data

systemd启动脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
cat > /lib/systemd/system/mysqld.service << EOF
#
# Simple MySQL systemd service file
#
# systemd supports lots of fancy features, look here (and linked docs) for a full list:
# http://www.freedesktop.org/software/systemd/man/systemd.exec.html
#
# Note: this file ( /usr/lib/systemd/system/mysql.service )
# will be overwritten on package upgrade, please copy the file to
#
# /etc/systemd/system/mysql.service
#
# to make needed changes.
#
# systemd-delta can be used to check differences between the two mysql.service files.
#

[Unit]
Description=MySQL Community Server
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target
Alias=mysql.service

[Service]
User=mysql
Group=mysql

PermissionsStartOnly=true

ExecStart=/data/soft/mysql/bin/mysqld --defaults-file=/data/db/mysql/my.cnf

TimeoutSec=600

PrivateTmp=false
LimitNOFILE=infinity
LimitMEMLOCK=infinity
EOF

chmod u+x /lib/systemd/system/mysqld.service

systemctl enable mysqld.service

修改连接用户

1
2
update mysql.user set Host='127.0.0.1' where User='root';
flush privileges;