Mysql-Percona mysql5.7简单安装

一、什么是Percona

单从mysql的角度来讲,可以把Percona理解为mysql的一个分支,因为mysql的源码是开源的,Percona就是在源码基础上对mysql做了一些改进,逐渐发展成了一条分支。其他分支还有mariadb等,都是mysql的分支,作为基础使用者,了解这么多就可以了,后续想深入了解,去看书吧。

二、Mysql5.7安装准备

1.基础信息:

(1)可参考官方文档【https://www.percona.com/doc/percona-server/5.7/installation/yum_repo.html】

(2)环境信息

系统:Centos7.3

Mysql:Percona的Mysql5.7

2.安装方式:

这里选择yum安装,原因是没有特殊需求,yum安装比较快

三、部署Mysql5.7

1.关闭selinux及firewalld防火墙

如果不关闭,启动会受到影响!!!别问我为什么知道!!!

# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux    
# setenforce 0  #关闭Selinux(强烈建议关闭)
# systemctl stop firewalld
# systemctl disable firewalld  #关闭firewalld防火墙

2.安装yum源

# yum -y install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm

3.安装Percona-server57(mysql5.7)

# yum -y install Percona-Server-server-57

4.创建mysql相关目录

# mkdir -p /opt/mysql/{mysql_data,mysql_log}  #创建mysql的数据目录和日志目录
# chown -R mysql:mysql /opt/mysql         #更改属主属组为mysql
# usermod -d /opt/mysql mysql           #将mysql用户的家目录改成工作目录(个人觉得应该修改)

4.修改配置文件

(1)清理不必要的原生配置文件

# cd /etc/
# rm -rf my.cnf my.cnf.d percona-server.cnf percona-server.conf.d  #我觉得这么一堆配置文件,不好维护,所以全部干掉

(2)建立mysql配置文件

cat <<EOF>>/etc/my.cnf
# Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208

[client]
port = 3306
socket = /tmp/mysql.sock

[mysql]

# CLIENT #
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8
prompt="\u@\h:\p \R:\m:\s [\d]>"

[mysqld]

# GENERAL #
user = mysql
default-storage-engine = InnoDB
character_set_server = utf8
socket = /tmp/mysql.sock
pid-file = /opt/mysql/mysql_log/mysqld.pid
log_timestamps = SYSTEM
server-id = 1001

# MyISAM #
key-buffer-size = 32M
myisam-recover-options = FORCE,BACKUP

# SAFETY #
max-allowed-packet = 32M
max-connect-errors = 1000000
sql-mode = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
innodb = FORCE

# DATA STORAGE #
datadir = /opt/mysql/mysql_data/

# BINARY LOGGING #
log-bin = /opt/mysql/mysql_log/mysql-bin
expire-logs-days = 15
sync-binlog = 1
binlog_format = ROW
log_bin_trust_function_creators = ON
binlog_rows_query_log_events = ON

# REPLICATION #
gtid_mode = ON
enforce_gtid_consistency = ON
log_slave_updates = ON
relay-log = /opt/mysql/mysql_log/relay-bin
relay_log_info_repository = TABLE
relay_log_recovery = ON
sync-relay-log = 10000
sync-relay-log-info = 10000
master_info_repository = TABLE
sync-master-info = 10000
binlog_group_commit_sync_delay = 0
binlog_group_commit_sync_no_delay_count = 0
transaction_write_set_extraction = 'XXHASH64'
binlog_transaction_dependency_tracking = WRITESET

# SLAVE #
slave-parallel-type = LOGICAL_CLOCK
slave-parallel-workers = 8
#read-only = 1
#super_read_only = 1
slave-net-timeout = 60
#skip-slave-start = 1
slave_pending_jobs_size_max = 64M

# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 8000
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 4096
table-open-cache = 4096
optimizer_switch = 'condition_fanout_filter=off,derived_merge=off'

# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 4
innodb-log-file-size = 512M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb_log_buffer_size = 8M
innodb-buffer-pool-size = 16G

# LOGGING #
log-error = /opt/mysql/mysql_log/mysql-error.log
log_error_verbosity = 1
slow-query-log = 1
slow-query-log-file = /opt/mysql/mysql_log/mysql-slow.log
max_slowlog_size = 1G
log_queries_not_using_indexes = OFF
EOF

注:这个配置文件仅供参考,可以根据自己需求进行更改,Percona的在线生成配置文件工具【http://tools.percona.com/】

 

(3)修改/etc/systemd/system/mysql.service

# vim /etc/systemd/system/mysql.service
修改以下行

  sed -i 's#/var/run/mysqld/mysqld.pid#/opt/mysql/mysql_log/mysqld.pid#g' /etc/systemd/system/mysql.service


  sed -i 's#/var/run/mysqld/mysqld.pid#/opt/mysql/mysql_log/mysqld.pid#g' /usr/lib/systemd/system/mysqld.service


  sed -i 's#LimitNOFILE = 5000#LimitNOFILE = 100000#g' /etc/systemd/system/mysql.service


  sed -i 's#LimitNOFILE = 5000#LimitNOFILE = 100000#g' /usr/lib/systemd/system/mysqld.service


# systemctl daemon-reload  #重新加载配置

4.启动mysql

# systemctl enable mysqld
# systemctl start mysqld

5.mysql简单初始化

(1)登录及修改初始密码

# grep -i 'password' /opt/mysql/mysql_log/mysql-error.log   #获取mysql初始密码
2018-04-19T04:07:12.534522Z 1 [Note] A temporary password is generated for root@localhost: er+Pezm/r31i

# mysql -u root -p'er+Pezm/r31i'  #登录mysql

# SET PASSWORD FOR root@'localhost' = 'MFdb@2018!'; #更改root密码

 

6.简单排错

如果启动时报错,可以使用以下方式排错

(1) 查看当前实例使用的配置文件是否是你定义的

# mysqld --verbose --help |grep -A 1 'Default options'
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

(2)查看输出日志

# cat /opt/mysql_log/mysql-error.log

(3)查看系统日志

# systemctl status mysqld  #这个看systemd的报错,个人觉得没什么卵用
# journalctl -b    #这个看系统输出的日志,信息量很大,比较有用
# journalctl -xe    #这个也是系统输出的日志,信息简略,有一些用

 

posted @ 2018-04-19 11:33  dingkailinux  阅读(6613)  评论(0编辑  收藏  举报