mysql5.7安裝及問題處理

datapeng發表於2017-10-09

一、軟體下載
登入到 http://dev.mysql.com/downloads/mysql/  ,選擇對應的版本進行下載。
二、建立mysql 使用者

[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql
[root@localhost ~]# passwd mysql
將tar 包複製到mysql的home 目錄下,進行解壓後得到的目錄 重新命名為 mysql-5.7.9

三、安裝資料庫
進入 /mysql/mysql5.7/bin
[mysql@localhost bin]$ ./mysql_install_db --user=mysql --basedir=/mysql/mysql5.7 --datadir=/mysql/mysql5.7/data
2017-04-19 06:49:00 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-04-19 06:49:07 [ERROR]   The bootstrap log isn't empty:
2017-04-19 06:49:07 [ERROR]   2017-04-19T14:49:01.852039Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2017-04-19T14:49:01.868000Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-04-19T14:49:01.868056Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-04-19T14:49:01.888730Z 0 [ERROR] Can't read from messagefile '/usr/share/mysql/english/errmsg.sys'

提示mysql_install_db 命令已棄用,使用mysqld

[mysql@localhost bin]$ ./mysqld --user=mysql --basedir=/mysql/mysql5.7 --datadir=/mysql/mysql5.7/data
[root@webtest1 mysql]#  bin/mysqld --initialize --user=mysql --basedir=/mysql/mysql5.7 --datadir=/mysql/mysql5.7/data

2017-04-19T14:50:18.145225Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-04-19T14:50:18.145526Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-04-19T14:50:18.797964Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-04-19T14:50:18.798019Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2017-04-19T14:50:18.798053Z 0 [Note] ./mysqld (mysqld 5.7.9) starting as process 3578 ...
2017-04-19T14:50:18.798104Z 0 [ERROR] Can't find error-message file '/mysql/mysql5.7share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2017-04-19T14:50:18.802586Z 0 [Note] InnoDB: PUNCH HOLE support not available
2017-04-19T14:50:18.802645Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-04-19T14:50:18.802656Z 0 [Note] InnoDB: Uses event mutexes
2017-04-19T14:50:18.802665Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
2017-04-19T14:50:18.802674Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-04-19T14:50:18.802682Z 0 [Note] InnoDB: Using Linux native AIO
2017-04-19T14:50:18.803153Z 0 [Note] InnoDB: Number of pools: 1
2017-04-19T14:50:18.803868Z 0 [Note] InnoDB: Using CPU crc32 instructions
2017-04-19T14:50:18.843406Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2017-04-19T14:50:18.860507Z 0 [Note] InnoDB: Completed initialization of buffer pool
2017-04-19T14:50:18.864349Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2017-04-19T14:50:18.878937Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2017-04-19T14:50:18.901395Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2017-04-19T14:50:18.901629Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2017-04-19T14:50:18.943961Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2017-04-19T14:50:18.945376Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2017-04-19T14:50:18.945403Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2017-04-19T14:50:18.952368Z 0 [Note] InnoDB: 5.7.9 started; log sequence number 2471242
2017-04-19T14:50:18.974882Z 0 [Note] InnoDB: Loading buffer pool(s) from /mysql/mysql5.7/data/ib_buffer_pool
2017-04-19T14:50:18.976665Z 0 [Note] InnoDB: Buffer pool(s) load completed at 151119  6:50:18
2017-04-19T14:50:18.978694Z 0 [Note] InnoDB: not started
2017-04-19T14:50:18.978878Z 0 [Note] Plugin 'FEDERATED' is disabled.
2017-04-19T14:50:18.983412Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2017-04-19T14:50:18.984289Z 0 [Warning] CA certificate ca.pem is self signed.
2017-04-19T14:50:19.003696Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2017-04-19T14:50:19.021246Z 0 [Note] IPv6 is available.
2017-04-19T14:50:19.021291Z 0 [Note]   - '::' resolves to '::';
2017-04-19T14:50:19.021299Z 0 [Note] Server socket created on IP: '::'.
2017-04-19T14:50:19.037949Z 0 [ERROR] Could not create unix socket lock file /var/lib/mysql/mysql.sock.lock.
2017-04-19T14:50:19.037976Z 0 [ERROR] Unable to setup unix socket lock file.
2017-04-19T14:50:19.037982Z 0 [ERROR] Aborting
2017-04-19T14:50:19.038004Z 0 [Note] Binlog end
2017-04-19T14:50:19.038084Z 0 [Note] Shutting down plugin 'ngram'
2017-04-19T14:50:19.038094Z 0 [Note] Shutting down plugin 'ARCHIVE'
2017-04-19T14:50:19.038098Z 0 [Note] Shutting down plugin 'partition'
2017-04-19T14:50:19.038102Z 0 [Note] Shutting down plugin 'BLACKHOLE'
2017-04-19T14:50:19.038106Z 0 [Note] Shutting down plugin 'CSV'
2017-04-19T14:50:19.038112Z 0 [Note] Shutting down plugin 'MEMORY'
2017-04-19T14:50:19.038118Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2017-04-19T14:50:19.038124Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
2017-04-19T14:50:19.038128Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2017-04-19T14:50:19.038131Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2017-04-19T14:50:19.038135Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2017-04-19T14:50:19.038138Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2017-04-19T14:50:19.038142Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2017-04-19T14:50:19.038145Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2017-04-19T14:50:19.038149Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2017-04-19T14:50:19.038152Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2017-04-19T14:50:19.038155Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2017-04-19T14:50:19.038159Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2017-04-19T14:50:19.038162Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2017-04-19T14:50:19.038165Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2017-04-19T14:50:19.038168Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2017-04-19T14:50:19.038172Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2017-04-19T14:50:19.038175Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2017-04-19T14:50:19.038179Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2017-04-19T14:50:19.038182Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2017-04-19T14:50:19.038186Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2017-04-19T14:50:19.038189Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2017-04-19T14:50:19.038192Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2017-04-19T14:50:19.038196Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2017-04-19T14:50:19.038199Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2017-04-19T14:50:19.038203Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2017-04-19T14:50:19.038206Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2017-04-19T14:50:19.038210Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2017-04-19T14:50:19.038213Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2017-04-19T14:50:19.038217Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2017-04-19T14:50:19.038221Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2017-04-19T14:50:19.038224Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2017-04-19T14:50:19.038228Z 0 [Note] Shutting down plugin 'InnoDB'
2017-04-19T14:50:19.038317Z 0 [Note] InnoDB: FTS optimize thread exiting.
2017-04-19T14:50:19.038421Z 0 [Note] InnoDB: Starting shutdown...
2017-04-19T14:50:19.151526Z 0 [Note] InnoDB: Dumping buffer pool(s) to /mysql/mysql5.7/data/ib_buffer_pool
2017-04-19T14:50:19.152515Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 151119  6:50:19
2017-04-19T14:50:20.802442Z 0 [Note] InnoDB: Shutdown completed; log sequence number 2471261
2017-04-19T14:50:20.811473Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2017-04-19T14:50:20.811528Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2017-04-19T14:50:20.811690Z 0 [Note] Shutting down plugin 'MyISAM'
2017-04-19T14:50:20.811730Z 0 [Note] Shutting down plugin 'sha256_password'
2017-04-19T14:50:20.811739Z 0 [Note] Shutting down plugin 'mysql_native_password'
2017-04-19T14:50:20.812061Z 0 [Note] Shutting down plugin 'binlog'
2017-04-19T14:50:20.813161Z 0 [Note]

在mysql5.7.17的安裝過程中,初始化引數使用了--initialize-insecure,這樣不會設定初始化root密碼,如果是 --initialize的話,會隨機生成一個密碼,這個密碼顯示在安裝過程最後
2017-04-19T14:50:20.813161Z 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: 2800d0e1-a3ec-11e7-a082-005056bb44b1.
2017-04-19T14:50:20.813161Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-04-19T14:50:20.813161Z 1 [Note] A temporary password is generated for : VfAG=aal=8;/

四、配置檔案
[root@localhost ~]# cd /mysql/mysql5.7/support-files/
[root@localhost support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? yes
[root@localhost support-files]# cp mysql.server /etc/init.d/mysql

[root@localhost ~]# vim /etc/init.d/mysql  
basedir=/mysql/mysql5.7
datadir=/mysql/mysql5.7/data

五、配置環境變數
[mysql@localhost ~]$ vi .bash_profile
PATH=$PATH:$HOME/bin
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
export MYSQL_HOME="/mysql/mysql5.7"
export PATH="$PATH:$MYSQL_HOME/bin"
~

六、新增開機啟動服務
chkconfig --add mysql
chkconfig mysql on

七、啟動mysql 
[root@localhost support-files]# su - mysql

報錯1
[mysql@localhost ~]$ service mysql start
/etc/init.d/mysql: line 256: my_print_defaults: command not found
Starting MySQL ERROR! Couldn't find MySQL server (/mysql/mysql5.7/bin/mysqld_safe)

啟動報錯了,原來是編輯/etc/init.d/mysql  檔案出錯了,修改為下面
vim /etc/init.d/mysql  
basedir=/mysql/mysql5.7
datadir=/mysql/mysql5.7/data
[mysql@localhost ~]$ service mysql start
Starting MySQL. SUCCESS!
再次啟動成功

報錯2
[mysql@goldqua1 ~]$ service mysqld start
Starting MySQL.2017-04-19T02:28:36.399450Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
The server quit without updating PID file (/mysql/mysql5.7/data/goldqua1.pid).[FAILED]
說明:mysqld_safe啟動指令碼預設的從/usr/local/mysql目錄中讀取另外一個啟動指令碼mysqld,因為我的安裝目錄為/mysql/mysql5.7product/5.6/mysql-1。所以找不到相關檔案。可以從兩個方面解決。

方法一:在/usr/local/mysql建立連結檔案

1.mkdir -p /usr/local/mysql/bin 
2.ln -s /mysql/mysql5.7/bin/mysqld /usr/local/mysql/bin/mysqld 

方法二:將mysqld_safe中的所有/usr/local/mysql目錄改為自己實際的安裝目錄

1.<pre name="code" class="sql">sed -i 's#/usr/local/mysql#/mysql/mysql5.7product/5.6/mysql-1#g' /mysql/mysql5.7product/5.6/mysql-1/bin/mysqld_safe 

再次啟動成功。

報錯3
mysql> show databases;
ERROR 1820 (HY000): Unknown error 1820
mysql> use mysql;
ERROR 1820 (HY000): Unknown error 1820
mysql> show databases;
ERROR 1820 (HY000): Unknown error 1820
這裡,不管怎麼執行都會報錯,挺奇怪的,後來發現需要首先執行密碼修改
mysql> set password=password('(Kl1b4X*');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

初始密碼:
[root@localhost bin]# cat /root/.mysql_secret
 # Password set for user at 2016-06-01 15:23:25
 ,xxxxxR5H9
 [root@localhost bin]# ./mysql -uroot -p


八、網路上出現的故障處理方法:

1、故障現象
[root@mysqltest mysqldata]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysqldata/mysql.sock' (111)

#故障環境
[root@mysqltest mysqldata]# more /etc/issue
CentOS release 5.9 (Final)
Kernel \r on an \m

 

2、故障分析
#檢視mysql例項的狀態
[root@mysqltest mysqldata]# netstat -ntlp  | grep 3306
tcp        0      0 :::3306                    :::*                        LISTEN      13001/mysqld

#檢視my.cnf關於socket的配置
[root@mysqltest mysqldata]# more /etc/my.cnf |grep sock
socket = /tmp/mysql.sock

#由上可知my.cnf中定義的為/tmp目錄下,而錯誤提示為/data/mysqldata/目錄下
#也就是說mysqld已經聲稱了正確的sock檔案,但客戶端連線還是從初始目錄去找sock檔案
#下面檢視後臺日誌,有個ERROR,是關於滿查詢日誌的,是由於目錄不存在而產生的錯誤,與當前故障無關
[root@mysqltest mysqldata]# more mysqltest.err
            ............
2014-10-11 13:17:21 13001 [Note] InnoDB: 5.6.12 started; log sequence number 1625997
/app/soft/mysql/bin/mysqld: File '/log/mysql_logs/slowquery.log' not found (Errcode: 2 - No such file or directory)
2014-10-11 13:17:21 13001 [ERROR] Could not use /log/mysql_logs/slowquery.log for logging (error 2). Turning logging off for the who
le duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
2014-10-11 13:17:21 13001 [Note] Server hostname (bind-address): '*'; port: 3306
2014-10-11 13:17:21 13001 [Note] IPv6 is available.
2014-10-11 13:17:21 13001 [Note]  - '::' resolves to '::';
2014-10-11 13:17:21 13001 [Note] Server socket created on IP: '::'.
2014-10-11 13:17:21 13001 [Note] Event Scheduler: Loaded 0 events
2014-10-11 13:17:21 13001 [Note] /app/soft/mysql/bin/mysqld: ready for connections.
Version: '5.6.12-log'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution


3、解決故障
a、透過配置my.cnf mysql選項socket檔案位置解決
#先停止mysql伺服器
[root@mysqltest mysqldata]# service mysqld stop
Shutting down MySQL.[  OK  ]

#修改my.cnf,如下
[root@mysqltest mysqldata]# vi /etc/my.cnf
[mysql]
no-auto-rehash
socket = /tmp/mysql.sock  #新增該行

#重啟mysql伺服器
[root@mysqltest mysqldata]# service mysqld start
Starting MySQL..[  OK  ]

#再次連線正常
[root@mysqltest mysqldata]# mysql -uroot -p
Enter password:
mysql> show variables like 'version';
+---------------+------------+
| Variable_name | Value      |
+---------------+------------+
| version      | 5.6.12-log |
+---------------+------------+

b、為socket檔案建立連結方式
[root@mysqltest mysqldata]# ln -s /tmp/mysql.sock /data/mysqldata/mysql.sock
ln: creating symbolic link `/data/mysqldata/mysql.sock' to `/tmp/mysql.sock': File exists
[root@mysqltest mysqldata]# rm mysql.sock    #上面提示檔案存在,所以刪除之前的mysql.sock檔案
[root@mysqltest mysqldata]# ln -s /tmp/mysql.sock /data/mysqldata/mysql.sock
[root@mysqltest mysqldata]# ls -hltr mysql.sock
lrwxrwxrwx 1 root root 15 Oct 11 14:00 mysql.sock -> /tmp/mysql.sock
[root@mysqltest mysqldata]# mysql -uroot -p
Enter password:
mysql> show variables like 'socket';
+---------------+-----------------+
| Variable_name | Value          |
+---------------+-----------------+
| socket        | /tmp/mysql.sock |
+---------------+-----------------+

九、mysql undo空間說明

[ERROR] InnoDB: Expected to open 4 undo tablespaces but was able to find only 0 undo tablespaces. Set the innodb_undo_tablespaces parameter to the correct value and retry. Suggested value is 0

報錯原因:
在初始化資料庫的時候沒有指定innodb_undo_tablespaces引數

解決方法:
在初始化資料庫的時候寫上--defaults-file引數,在對應的配置檔案中寫上對應的innodb_undo_tablespaces引數
[mysql@localhost mysql_data]$ vi /tmp/my.cnf
##InnoDB engine undo log related setting
innodb_undo_directory                           = /u01/mysql_data
innodb_undo_tablespaces                         = 4

[mysql@localhost percona]$ bin/mysqld --defaults-file=/tmp/my.cnf --user=mysql --initialize-insecure

注意初始化資料庫語句的寫法,將--defaults-file放到語句最後會導致配置檔案中的引數不會生效

十、引數說明

# MySql5.7配置檔案my.cnf設定

[client]

port = 3306

socket = /tmp/mysql.sock

[mysqld]

###############################基礎設定#####################################

#Mysql服務的唯一編號 每個mysql服務Id需唯一

server-id = 1

#服務埠號 預設3306

port = 3306

#mysql安裝根目錄

basedir = /opt/mysql
#mysql資料檔案所在位置

datadir = /opt/mysql/data
#臨時目錄 比如load data infile會用到
tmpdir  = /tmp
#設定socke檔案所在目錄

socket  = /tmp/mysql.sock

#主要用於MyISAM儲存引擎,如果多臺伺服器連線一個資料庫則建議註釋下面內容

skip-external-locking
#只能用IP地址檢查客戶端的登入,不用主機名

skip_name_resolve = 1
#事務隔離級別,預設為可重複讀,mysql預設可重複讀級別(此級別下可能引數很多間隙鎖,影響效能)

transaction_isolation = READ-COMMITTED
#資料庫預設字符集,主流字符集支援一些特殊表情符號(特殊表情符佔用4個位元組)

character-set-server = utf8mb4

#資料庫字符集對應一些排序等規則,注意要和character-set-server對應

collation-server = utf8mb4_general_ci

#設定client連線mysql時的字符集,防止亂碼

init_connect='SET NAMES utf8mb4'
#是否對sql語句大小寫敏感,1表示不敏感

lower_case_table_names = 1
#最大連線數

max_connections = 400

#最大錯誤連線數

max_connect_errors = 1000
#TIMESTAMP如果沒有顯示宣告NOT NULL,允許NULL值

explicit_defaults_for_timestamp = true
#SQL資料包傳送的大小,如果有BLOB物件建議修改成1G

max_allowed_packet = 128M
#MySQL連線閒置超過一定時間後(單位:秒)將會被強行關閉

#MySQL預設的wait_timeout  值為8個小時, interactive_timeout引數需要同時配置才能生效

interactive_timeout = 1800

wait_timeout = 1800

#內部記憶體臨時表的最大值 ,設定成128M。

#比如大資料量的group by ,order by時可能用到臨時表,

#超過了這個值將寫入磁碟,系統IO壓力增大

tmp_table_size = 134217728

max_heap_table_size = 134217728
#禁用mysql的快取查詢結果集功能
#後期根據業務情況測試決定是否開啟
#大部分情況下關閉下面兩項
query_cache_size = 0
 query_cache_type = 0


##----------------------------使用者程式分配到的記憶體設定BEGIN-----------------------------##

##每個session將會分配引數設定的記憶體大小

#用於表的順序掃描,讀出的資料暫存於read_buffer_size中,當buff滿時或讀完,將資料返回上層呼叫者

#一般在128kb ~ 256kb,用於MyISAM

#read_buffer_size = 131072

#用於表的隨機讀取,當按照一個非索引欄位排序讀取時會用到,

#一般在128kb ~ 256kb,用於MyISAM

#read_rnd_buffer_size = 262144

#order by或group by時用到

#建議先調整為2M,後期觀察調整

sort_buffer_size = 2097152

#一般資料庫中沒什麼大的事務,設成1~2M,預設32kb

binlog_cache_size = 524288

##---------------------------使用者程式分配到的記憶體設定END-------------------------------##
#在MySQL暫時停止響應新請求之前的短時間內多少個請求可以被存在堆疊中

#官方建議back_log = 50 + (max_connections / 5),封頂數為900

back_log = 130
############################日  志 設定##########################################

#資料庫錯誤日誌檔案

log_error = error.log
#慢查詢sql日誌設定

slow_query_log = 1

slow_query_log_file = slow.log

#檢查未使用到索引的sql

log_queries_not_using_indexes = 1

#針對log_queries_not_using_indexes開啟後,記錄慢sql的頻次、每分鐘記錄的條數

log_throttle_queries_not_using_indexes = 5

#作為從庫時生效,從庫複製中如何有慢sql也將被記錄

log_slow_slave_statements = 1

#慢查詢執行的秒數,必須達到此值可被記錄

long_query_time = 8

#檢索的行數必須達到此值才可被記為慢查詢

min_examined_row_limit = 100
#mysql binlog日誌檔案儲存的過期時間,過期後自動刪除

expire_logs_days = 5
############################主從複製 設定########################################

#開啟mysql binlog功能

log-bin=mysql-bin

#binlog記錄內容的方式,記錄被操作的每一行

binlog_format = ROW

#對於binlog_format = ROW模式時,減少記錄日誌的內容,只記錄受影響的列

binlog_row_image = minimal
#master status and connection information輸出到表mysql.slave_master_info中

master_info_repository = TABLE

#the slave's position in the relay logs輸出到表mysql.slave_relay_log_info中

relay_log_info_repository = TABLE
#作為從庫時生效,想進行級聯複製,則需要此引數

log_slave_updates
#作為從庫時生效,中繼日誌relay-log可以自我修復

relay_log_recovery = 1

#作為從庫時生效,主從複製時忽略的錯誤

slave_skip_errors = ddl_exist_errors
##---redo log和binlog的關係設定BEGIN---##

#(步驟1) prepare dml相關的SQL操作,然後將redo log buff中的快取持久化到磁碟

#(步驟2)如果前面prepare成功,那麼再繼續將事務日誌持久化到binlog

#(步驟3)如果前面成功,那麼在redo log裡面寫上一個commit記錄

#當innodb_flush_log_at_trx_commit和sync_binlog都為1時是最安全的,

#在mysqld服務崩潰或者伺服器主機crash的情況下,binary log只有可能丟失最多一個語句或者一個事務。

#但是都設定為1時會導致頻繁的io操作,因此該模式也是最慢的一種方式。

#當innodb_flush_log_at_trx_commit設定為0,mysqld程式的崩潰會導致上一秒鐘所有事務資料的丟失。

#當innodb_flush_log_at_trx_commit設定為2,只有在作業系統崩潰或者系統掉電的情況下,上一秒鐘所有事務資料才可能丟失。

#commit事務時,控制redo log buff持久化磁碟的模式 預設為1

innodb_flush_log_at_trx_commit = 2

#commit事務時,控制寫入mysql binlog日誌的模式 預設為 0

#innodb_flush_log_at_trx_commit和sync_binlog都為1時,mysql最為安全但效能上壓力也是最大

sync_binlog = 1

##---redo log 和 binlog的關係設定END---##
############################Innodb設定##########################################

#資料塊的單位8k,預設是16k,16kCPU壓力稍小,8k對select的吞吐量大

#innodb_page_size的引數值也影響最大索引長度,8k比16k的最大索引長度小

#innodb_page_size = 8192

#一般設定物理儲存的60% ~ 70%

innodb_buffer_pool_size = 1G
#5.7.6之後預設16M

#innodb_log_buffer_size = 16777216

#該引數針對unix、linux,window上直接註釋該引數.預設值為NULL

#O_DIRECT減少作業系統級別VFS的快取和Innodb本身的buffer快取之間的衝突

innodb_flush_method = O_DIRECT
#此格式支援壓縮, 5.7.7之後為預設值

innodb_file_format = Barracuda
#CPU多核處理能力設定,假設CPU是2顆4核的,設定如下

#讀多,寫少可以設成2:6的比例

innodb_write_io_threads = 4

innodb_read_io_threads = 4
#提高重新整理髒頁數量和合並插入數量,改善磁碟I/O處理能力

#預設值200(單位:頁)

#可根據磁碟近期的IOPS確定該值

innodb_io_capacity = 500

#為了獲取被鎖定的資源最大等待時間,預設50秒,超過該時間會報如下錯誤:

# ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

innodb_lock_wait_timeout = 30
#調整buffer pool中最近使用的頁讀取並dump的百分比,透過設定該引數可以減少轉儲的page數

innodb_buffer_pool_dump_pct = 40
#設定redoLog檔案所在目錄, redoLog記錄事務具體操作內容

innodb_log_group_home_dir = /opt/mysql/redolog/
#設定undoLog檔案所在目錄, undoLog用於事務回滾操作

innodb_undo_directory = /opt/mysql/undolog/
#在innodb_log_group_home_dir中的redoLog檔案數, redoLog檔案內容是迴圈覆蓋寫入。

innodb_log_files_in_group = 3
#MySql5.7官方建議儘量設定的大些,可以接近innodb_buffer_pool_size的大小

#之前設定該值較大時可能導致mysql當機恢復時間過長,現在恢復已經加快很多了

#該值減少髒資料重新整理到磁碟的頻次

#最大值innodb_log_file_size * innodb_log_files_in_group <= 512GB,單檔案<=256GB

innodb_log_file_size = 1024M
#設定undoLog檔案所佔空間可以回收

#5.7之前的MySql的undoLog檔案一直增大無法回收

innodb_undo_log_truncate = 1

innodb_undo_tablespaces = 3

innodb_undo_logs = 128
#5.7.7預設開啟該引數 控制單列索引長度最大達到3072

#innodb_large_prefix = 1
#5.7.8預設為4個, Inodb後臺清理工作的執行緒數

#innodb_purge_threads = 4
#透過設定配置引數innodb_thread_concurrency來限制併發執行緒的數量,

#一旦執行執行緒的數量達到這個限制,額外的執行緒在被放置到對佇列中之前,會睡眠數微秒,

#可以透過設定引數innodb_thread_sleep_delay來配置睡眠時間

#該值預設為0,在官方doc上,對於innodb_thread_concurrency的使用,也給出了一些建議:

#(1)如果一個工作負載中,併發使用者執行緒的數量小於64,建議設定innodb_thread_concurrency=0;

#(2)如果工作負載一直較為嚴重甚至偶爾達到頂峰,建議先設定innodb_thread_concurrency=128,

###並透過不斷的降低這個引數,96, 80, 64等等,直到發現能夠提供最佳效能的執行緒數

#innodb_thread_concurrency = 0

#強所有發生的死鎖錯誤資訊記錄到error.log中,之前透過命令列只能檢視最近一次死鎖資訊

innodb_print_all_deadlocks = 1
############################其他內容 設定##########################################

[mysqldump]

quick

max_allowed_packet = 128M

[mysql]

no-auto-rehash

[myisamchk]

key_buffer_size = 20M

sort_buffer_size = 256k

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

#增加每個程式的可開啟檔案數量.
open-files-limit = 28192

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29371470/viewspace-2145769/,如需轉載,請註明出處,否則將追究法律責任。

相關文章