基於centos 7的mysql 5.7自動化安裝,這裏順便說一下my.cnf裏的一些定義的參數 好比下面兩個 innodb_buffer_pool_dump_at_shutdown=1 #關閉時把熱數據dump到本地磁盤 innodb_buffer_pool_load_at_startup=1 #啓動時把熱數據加載到內存 由於mysql重啓時候會面臨一個問題,就是如何將以前頻繁訪問的數據從新加載回Buffer中, 也就是說如何對InnoDB Buffer Pool進行預熱來快速恢復以前的性能狀態。 增長了undo log的自定義目錄,由於把undo log從共享表空間ibdata1裏拆分出去的話,須要 在my.cnf裏提早指定好,否則等數據庫啓動好後再指定會報錯。 innodb_undo_log_truncate=1 #開啓在線回收 innodb_max_undo_los_size=1G #這個就是閾值(默認是1GB)時,會觸發truncate回收動做。 而後說一下,下面這個配置 innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G 由於ibtmp1文件是 MySQL5.7的新特性,MySQL5.7使用了獨立的臨時表空間來存儲臨時表數據, 初始化12M,且默認無上限,我這裏設定了最高不能超過5g,釋放這個臨時表空間惟一的辦法就 是啓數據庫。 innodb_read_io_threads, innodb_write_io_threads: 文件讀寫的 I/O 線程數 可根據併發量和 CPU 核心數適當調整 也不要再去糾結 query_cache_size和query_cache_type這兩個參數了,這對於mysql來講就是雞肋 並且默認就是關閉的,建議採用默認值,也就是設置爲0,關閉 Redo logs 記錄了全部的數據變動 恢復時間再也不是一個問題 innodb_log_file_size = 2047M before 5.6 innodb_log_file_size>= 2047M from 5.6 So ... 越大系統性能更穩定 這個你們應該都知道 innodb_buffer_pool_size 你懂的,本身物理內存大小的50~70% 最後還有一點,新版的mysql默認監聽在IPv6上,記得關閉掉它 bind-address=0.0.0.0 當mysql 數據庫發生死鎖時, innodb status 裏面會記錄最後一次死鎖的相關信息,但mysql 錯誤日誌裏面 不會記錄死鎖相關信息,要想記錄,啓動 innodb_print_all_deadlocks 參數 。 當系統併發很高時,不少的線程等待同一個行鎖,死鎖檢測可能會拖慢系統,這個時候關閉死鎖檢測可能更好 innodb_print_all_deadlocks = 1 最後說一句:MySQL默認的隔離級別不適合大部分的應用場景,並且容易發生死鎖,因此我這裏改爲了read-committed 好了,最後就是安裝步驟了,其實都已經腳本化了。 mkdir -p /home/tools cd /home/tools yum -y install numactl libaio wget http://god.nongdingbang.net/downloads/mysql-5.7-el7.tgz && tar zxvf mysql-5.7-el7.tgz if [ $? -eq 0 ];then rpm -Uvh mysql*.rpm fi mkdir -p /data/{mysql_data,mysql_log,mysql_slow,mysql_undo} chown -R mysql.mysql /data/* cat >/etc/my.cnf<<EOF [client] port=3306 socket=/tmp/mysql.sock [mysql] no-auto-rehash [mysqld] port=3306 character-set-server=utf8 socket=/tmp/mysql.sock datadir=/data/mysql_data explicit_defaults_for_timestamp=true lower_case_table_names=1 sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' bind-address=0.0.0.0 back_log=103 max_connections=500 max_connect_errors=100000 table_open_cache=512 external-locking=FALSE max_allowed_packet=128M sort_buffer_size=2M join_buffer_size=2M thread_cache_size=51 query_cache_size=0 query_cache_type=0 #query_cache_limit=4M transaction_isolation=READ-COMMITTED tmp_table_size=96M max_heap_table_size=96M log-error=/data/mysql_log/error.log ###***slowqueryparameters long_query_time=2 slow_query_log=1 slow_query_log_file=/data/mysql_slow/slow.log ###***binlogparameters log-bin=/data/mysql_log/mysql-bin binlog_cache_size=1M max_binlog_cache_size=4096M max_binlog_size=1024M binlog_format=ROW binlog_row_image=full expire_logs_days=3 sync_binlog=0 ###***undolog innodb_undo_directory=/data/mysql_undo innodb_undo_logs=128 innodb_undo_tablespaces=4 innodb_undo_log_truncate=1 innodb_max_undo_log_size=1G innodb_purge_rseg_truncate_frequency #***MyISAMparameters key_buffer_size=16M read_buffer_size=1M read_rnd_buffer_size=16M bulk_insert_buffer_size=1M ###***master-slavereplicationparameters server-id=1 #read-only=1 #replicate-wild-ignore-table=mysql.% ###***Multi-Threaded Slave #slave-parallel-type=LOGICAL_CLOCK #slave-parallel-workers=16 #master_info_repository=TABLE #relay_log_info_repository=TABLE relay_log_recovery=ON #***Innodbstorageengineparameters innodb_buffer_pool_dump_at_shutdown=1 innodb_buffer_pool_load_at_startup=1 innodb_buffer_pool_size=16G innodb_data_file_path=ibdata1:10M:autoextend innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G #innodb_file_io_threads=8 innodb_thread_concurrency=0 innodb_flush_log_at_trx_commit=2 innodb_log_buffer_size=16M innodb_log_file_size=2048M innodb_log_files_in_group=2 innodb_max_dirty_pages_pct=75 innodb_buffer_pool_dump_pct=50 innodb_lock_wait_timeout=50 innodb_file_per_table=on innodb_flush_neighbors=0 innodb_flush_method=O_DIRECT innodb_read_io_threads=16 innodb_write_io_threads=16 innodb_io_capacity = 5000 #innodb_print_all_deadlocks = 1 wait_timeout = 14400 interactive_timeout = 14400 [mysqldump] quick max_allowed_packet=128M [myisamchk] key_buffer=16M sort_buffer_size=16M read_buffer=8M write_buffer=8M [mysqld_safe] open-files-limit=28192 log-error=/data/mysql_log/error.log pid-file=/data/mysql_data/mysqld.pid EOF ## Initialize MySQL configuration mysqld --defaults-file=/etc/my.cnf --user=mysql \ --datadir=/data/mysql_data --initialize-insecure ## Start mysql systemctl restart mysqld && systemctl enable mysqld ## Setting root's password for mysql ############################################## read -s -p "Enter password : " password mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '"$password"';" mysql -uroot -p"$password" -Dmysql -e "select user,host,authentication_string,password_expired from user;" mysql -uroot -p"$password" -e "flush privileges;" echo Your password is "$password"