1、什麼是Perconahtml
單從mysql的角度來說,能夠把Percona理解爲mysql的一個分支,由於mysql的源碼是開源的,Percona就是在源碼基礎上對mysql作了一些改進,逐漸發展成了一條分支。其餘分支還有mariadb等,都是mysql的分支,做爲基礎使用者,瞭解這麼多就能夠了,後續想深刻了解,去看書吧。mysql
2、Mysql5.7安裝準備linux
1.基礎信息:sql
(1)可參考官方文檔【https://www.percona.com/doc/percona-server/5.7/installation/yum_repo.html】vim
(2)環境信息socket
系統:Centos7.3工具
Mysql:Percona的Mysql5.7spa
2.安裝方式:日誌
這裏選擇yum安裝,緣由是沒有特殊需求,yum安裝比較快code
3、部署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 #這個也是系統輸出的日誌,信息簡略,有一些用