下面開始優化下my.conf文件(這里的優化只是在mysql本身的優化,之前安裝的時候也要有優化)
cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
##################################################
#innodb
user=mysql
innodb_buffer_pool_size=6G
innodb_log_file_size=4G
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit=2
innodb_file_per_table=1
innodb_file_io_threads=4
innodb_flush_method=O_DIRECT
innodb_io_capacity=2000
innodb_io_capacity_max=6000
innodb_lru_scan_depth=2000
innodb_thread_concurrency = 0
innodb_additional_mem_pool_size=16M
innodb_autoinc_lock_mode = 2
##################################################
# Binary log/replication
log-bin
sync_binlog=1
sync_relay_log=1
relay-log-info-repository=TABLE
master-info-repository=TABLE
expire_logs_days=7
binlog_format=ROW
transaction-isolation=READ-COMMITTED
#################################################
#cache
tmp_table_size=512M
character-set-server=utf8
collation-server=utf8_general_ci
skip-external-locking
back_log=1024
key_buffer_size=1024M
thread_stack=256k
read_buffer_size=8M
thread_cache_size=64
query_cache_size=128M
max_heap_table_size=256M
query_cache_type=1
binlog_cache_size = 2M
table_open_cache=128
thread_cache=1024
thread_concurrency=8
wait_timeout=30
join_buffer_size = 1024M
sort_buffer_size = 8M
read_rnd_buffer_size = 8M
#################################################
#connect
max-connect-errors=100000
max-connections=1000
#################################################
explicit_defaults_for_timestamp=true
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
##################################################
# Binary log/replication(這里主要是復制功能,也就是主從,提前配置好,后面講主從配置)
#二進制日志
log-bin
#為了在最大程序上保證復制的InnoDB事務持久性和一致性
sync_binlog=1
sync_relay_log=1
#啟用此兩項,可用于實現在崩潰時保證二進制及從服務器安全的功能
relay-log-info-repository=TABLE
master-info-repository=TABLE
#設置清除日志時間
expire_logs_days=7
#行復制
binlog_format=ROW
#mysql數據庫事務隔離級別有四種(READ UNCOMMITTED,READ COMMITTED,REPEATABLE READ,SERIALIZABLE)
transaction-isolation=READ-COMMITTED
#cache
#內部內存臨時表的最大值
tmp_table_size=512M
character-set-server=utf8
collation-server=utf8_general_ci
#即跳過外部鎖定
skip-external-locking
#MySQL能暫存的連接數量(根據實際設置)
back_log=1024
#指定索引緩沖區的大小,只對MyISAM表起作用,這里寫上也沒有關系
key_buffer_size=1024M
#這條指令限定用于每個數據庫線程的棧大小
thread_stack=256k
#當一個查詢不斷地掃描某一個表,MySQL會為它分配一段內存緩沖區
read_buffer_size=8M
#線程緩存
thread_cache_size=64
#查詢緩存大小
query_cache_size=128M
#內部內存臨時表的最大值,每個線程都要分配
max_heap_table_size=256M
#將查詢結果放入查詢緩存中
query_cache_type=1
#代表在事務過程中容納二進制日志SQL語句的緩存大小
binlog_cache_size = 2M
#同樣是緩存表大小
table_open_cache=128
#緩存線程
thread_cache=1024
#推薦設置為服務器 CPU核數的2倍
thread_concurrency=8
wait_timeout=30
#表和表聯接的緩沖區的大小
join_buffer_size = 1024M
#是一個connection級參數,在每個connection第一次需要使用這個buffer的時候,一次性分配設置的內存
sort_buffer_size=8M
#隨機讀取數據緩沖區使用內存
read_rnd_buffer_size = 8M
#connect
#是一個MySQL中與安全有關的計數器值,它負責阻止過多嘗試失敗的客戶端以防止暴力破解密碼
max-connect-errors=100000
#連接數
max-connections=1000
#開啟查詢緩存
explicit_defaults_for_timestamp=true
#mysql服務器能夠工作在不同的模式下,并能針對不同的客戶端以不同的方式應用這些模式
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
下面列出了對性能優化影響較大的主要變量,主要分為連接請求的變量和緩沖區變量。
1. 連接請求的變量:
1) max_connections
MySQL的最大連接數,增加該值增加mysqld 要求的文件描述符的數量。如果服務器的并發連接請求量比較大,建議調高此值,以增加并行連接數量,當然這建立在機器能支撐的情況下,因為如果連接數越多, 介于MySQL會為每個連接提供連接緩沖區,就會開銷越多的內存,所以要適當調整該值,不能盲目提高設值。
數值過小會經常出現ERROR 1040: Too many connections錯誤,可以過'conn%'通配符查看當前狀態的連接數量,以定奪該值的大小。
show variables like ‘max_connections' 最大連接數
show status like ‘max_used_connections'響應的連接數
如下:
mysql> show variables like ‘max_connections‘;
+―――――――
主站蜘蛛池模板:
台中县|
泸州市|
龙陵县|
镇雄县|
浮梁县|
安陆市|
碌曲县|
宁晋县|
宁明县|
新疆|
方城县|
淳化县|
平塘县|
白水县|
宁德市|
辛集市|
墨脱县|
屏山县|
连城县|
合川市|
洪泽县|
隆德县|
武义县|
达孜县|
乌兰察布市|
金秀|
泊头市|
拉孜县|
嘉祥县|
息烽县|
周宁县|
仪陇县|
民县|
东丽区|
仙桃市|
正蓝旗|
济阳县|
岑溪市|
扎鲁特旗|
和龙市|
弋阳县|