秦悦明的运维笔记

mysql-5.7编译安装

1. 编译

下载:
直接用国内的源,速度杠杠的:

1
http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.17.tar.gz

最新源码包是

1
2
http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.18.tar.gz
http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.18.tar.gz

依赖(centos7为例):

1
sudo yum -y install make gcc-c++ cmake bison-devel bison ncurses-devel

编译跟5.6稍微有点不一样,依赖新版的boost了。不要cmake时候自动下载,会被墙掉。直接下载boost版本的源码包就行了,剩下的套路跟5.6的一样。

1
2
3
4
cd BUILD
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql57 -DWITH_BOOST=../boost ..
make
make install

2.单实例初始化和运行

mysql_install_db已经被废弃了。直接用

1
2
3
4
5
6
7
# bin/mysqld --initialize --user=mysql --datadir=/vdb/mysql1
2017-06-19T01:18:19.299580Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-06-19T01:18:19.458771Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-06-19T01:18:19.482412Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-06-19T01:18:19.537139Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2de7b52f-548d-11e7-b57b-52560acdcad4.
2017-06-19T01:18:19.537944Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-06-19T01:18:19.538602Z 1 [Note] A temporary password is generated for root@localhost: C#lF1kb*KkV/

运行,

1
2
3
4
5
6
7
8
9
10
11
# cp support-files/mysql.server .
修改mysql.server中的
basedir=xxx
datadir=xxx
修改 /etc/my.cnf 中配置。
vim /etc/my.cnf
# ./mysql.server start
Starting MySQL.Logging to '/vdb/mysql1/10-205-202-212.err'. [ OK ]

用上面系统生成的随机密码进去,然后修改成自己的密码完成整个初始化

1
alter user root@localhost identified by '123123';

3.多实例部署

主要是用到了mysqld_multi,要在my.cnf里面填上多个实例的信息,格式如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[mysqld_multi]
mysqld = /usr/local/mysql57/bin/mysqld_safe
mysqladmin = /usr/local/mysql57/bin/mysqladmin
user = multi_admin
password = my_password
[mysqld2]
socket = /tmp/mysql.sock2
port = 3307
pid-file = /usr/local/mysql57/data2/hostname.pid2
datadir = /usr/local/mysql57/data2
language = /usr/local/mysql57/share/mysql/english
user = unix_user1
[mysqld3]
mysqld = /path/to/mysqld_safe
ledir = /path/to/mysqld-binary/
mysqladmin = /path/to/mysqladmin
socket = /tmp/mysql.sock3
port = 3308
pid-file = /usr/local/mysql57/data3/hostname.pid3
datadir = /usr/local/mysql57/data3
language = /usr/local/mysql57/share/mysql/swedish
user = unix_user2

用 mysqld_multi –example可以直接查看。很方便,mysqld_multi里面的user和password 主要是用来关闭实例时候用的mysql 用户,所以先要附权限

1
GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'password'

然后配置上就可以了~很方便。