MySQL5.7.20源码安装
1.下载解压
cd /data/app/mysql5.7
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20.tar.gz
tar -zxvf mysql-5.7.20.tar.gz
2.添加mysql用户组并添加mysql用户,并且不允许登录
groupadd mysql
useradd -r -g mysql -s /bin/false -M mysql
3.创建安装目录
mkdir -p /data/app/mysql5.7/{data,boost}
4.cmake配置
cmake . -DCMAKE_INSTALL_PREFIX=/data/app/mysql5.7 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DCOMPILATION_COMMENT='MySQL 5.7.20' -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/data/app/mysql5.7/boost -DMYSQL_DATADIR=/data/app/mysql5.7/data -DSYSCONFDIR=/data/app/mysql5.7 -DMYSQL_UNIX_ADDR=/data/app/mysql5.7/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1
5.编译安装
make && make install
6.权限绑定
chown -R mysql:mysql /data/app/mysql5.7
7.初始化(会生成初始化密码,需要记住)
/data/app/mysql5.7/bin/mysqld --initialize --user=mysql --basedir=/data/app/mysql5.7 --datadir=/data/app/mysql5.7/data
8.启动
/data/app/mysql5.7/bin/mysqld_safe &
9.修改密码
/data/app/mysql5.7/bin/mysql -uroot -p初始化密码
alter user 'root'@'localhost' identified by '123456';
10.加入系统服务
cp /data/app/mysql5.7/support-files/mysql.server /etc/init.d/mysqld5.7
chmod +x /etc/init.d/mysqld5.7
/etc/init.d/mysqld5.7 start|stop|restart
【扩展】pt-query-digest用法示例
1.直接分析慢查询文件:
pt-query-digest slow.log > slow_report.log
2.分析最近12小时内的查询:
pt-query-digest --since=12h slow.log > slow_report2.log
3.分析指定时间范围内的查询:
pt-query-digest slow.log --since '2017-01-07 09:30:00' --until '2017-01-07 10:00:00'> > slow_report3.log
4.分析指含有select语句的慢查询
pt-query-digest --filter '$event->{fingerprint} =~ m/^select/i' slow.log> slow_report4.log
5.针对某个用户的慢查询
pt-query-digest --filter '($event->{user} || "") =~ m/^root/i' slow.log> slow_report5.log
6.查询所有所有的全表扫描或full join的慢查询
pt-query-digest --filter '(($event->{Full_scan} || "") eq "yes") ||(($event->{Full_join} || "") eq "yes")' slow.log> slow_report6.log
7.把查询保存到query_review表
pt-query-digest --user=root –password=abc123 --review h=localhost,D=test,t=query_review--create-review-table slow.log
8.把查询保存到query_history表
pt-query-digest --user=root –password=abc123 --review h=localhost,D=test,t=query_history--create-review-table slow.log_0001
pt-query-digest --user=root –password=abc123 --review h=localhost,D=test,t=query_history--create-review-table slow.log_0002
9.通过tcpdump抓取mysql的tcp协议数据,然后再分析
tcpdump -s 65535 -x -nn -q -tttt -i any -c 1000 port 3306 > mysql.tcp.txt
pt-query-digest --type tcpdump mysql.tcp.txt> slow_report9.log
10.分析binlog
mysqlbinlog mysql-bin.000093 > mysql-bin000093.sql
pt-query-digest --type=binlog mysql-bin000093.sql > slow_report10.log
11.分析general log
pt-query-digest --type=genlog localhost.log > slow_report11.log