Foreword: mysql parameter optimization is a difficult thing for novices to understand. In fact, this parameter optimization is a very complicated thing. For different websites, their online volume, number of visits, number of posts, network conditions, and machine hardware configuration it's all related,
Optimization cannot be done at one time, and requires continuous observation and debugging to get the best results.
Reference blog: https://blog.csdn.net/xuxile/article/details/53410562
http://www.jb51.net/article/48082.htm
Open # vi /etc/my.cnf
[client] #client
port = 3306 #Database port 3306
socket = /tmp/mysql.sock #mysql socket, use socket connection under multiple instances
[mysql]
default-character-set = utf-8 #character set
[mysqld]
port = 3306
socket = /tmp/mysql.sock
character_set_server = utf-8
#file
basedir = /usr/local/mysql #mysql installation directory
datadir = /data/mysql #Data file path
pid-file = /data/mysql/mysql.pid #mysql process
log_error = /data/mysql/log/mysql.err #mysql error log path
#skip-grant-tables #When you forget the root password, you can connect to mysql and reset the password after starting with --skip-grant--tables
slow_query_log = 1 #Enable slow query log
slow_query_log_file = /data/mysql/log/slowq.log #Slow query log path
long_query_time = 1 #Slow query time 1 second
#temp
max_tmp_tables = 64 #Maximum number of open temporary tables
max_heap_table_size = 1G #Create the size of the memory table
tmp_table_size = 512M #Maximum value of memory temporary table
slave_load_tmpdir = /data/mysql/log #slave temporary directory path
tmpdir = /data/mysql/log #Temporary directory path
#session
back_log = 8192 #mysql indicates how many requests can be temporarily stacked before stopping new requests
skip-name-resolve #Skip reverse resolution
max_allowed_packet = 32M #The client receives the maximum bytes session value
max_connections = 16000 #Maximum number of connections
max_connect_errors = 10000 #Maximum number of error connections, if it is full, it needs to be cleared by flush hosts
wait_timeout = 28800 #Wait timeout time
binlog_cache_size = 1M #binlog cache size
table_open_cache = 1024 #Table buffer size
thread_concurrency = 4 #Thread concurrency
thread_cache_size = 128 #Thread buffer size
thread_handling = pool-of-threads #Open the thread pool
thread_pool_high_prio_mode = none #New connections are prioritized according to thread_pool_high_prio_mode
thread_pool_idle_timeout = 28800 #Idle thread timeout
thread_pool_oversubscribe = 20 #Maximum number of tasks to support running
#max_statement_time = 5000 #Control the maximum execution time of the query in mysql, in milliseconds
query_cache_type = 0 #whether the query buffer is open 0: close 1: open 2: demand
query_cache_size = 0 #query buffer size
key_buffer_size = 128M #index buffer size
myisam_sort_buffer_size = 16M #MyISAM sort buffer size
read_buffer_size = 8M #sequential read buffer Flush size read_rnd_buffer_size = 4M #Random
read buffer size sort_buffer_size = 16M #sort buffer size join_buffer_size = 16M #join buffer size
# innodb
default_storage_engine = InnoDB #默认存储引擎
innodb_data_home_dir = /data/mysql/log #innodb存储引擎共享表空间路径,即:ibdata
innodb_data_file_path = ibdata1:256M:autoextend #innodb存储引擎大小,自增
innodb_log_group_home_dir = /data/mysql/log #ib_logfile日志路径
innodb_log_files_in_group = 2 #ib_logfile两组,每组两个
innodb_log_file_size = 512M #ib_logfile大小
innodb_log_buffer_size = 8M #日志缓冲区大小
innodb_flush_log_at_trx_commit = 2 #等于2时,不写硬盘而是写入系统缓存,日志仍会每秒写到硬盘
innodb_flush_method = O_DIRECT #向文件写入数据,只有数据写到了磁盘,写入操作完成(write返回成功)
innodb_lock_wait_timeout = 50 #innodb引擎锁等待超时时间
#innodb_thread_concurrency = 16 #innodb线程并发数
innodb_buffer_pool_size = 44G #innodb存储引擎缓冲区大小
innodb_additional_mem_pool_size = 20M #用来设置 InnoDB 存储的数据目录信息和其它内部数据结构的内存池大小
innodb_io_capacity = 1500 #控制Innodb checkpoint时的IO能力
innodb_use_native_aio = 1 #控制是否启用Native AIO,默认开启。官方的测试显示,启用Native AIO,恢复速度可以提高75%
innodb_file_per_table = 1 #innodb引擎使用独立的表空间
innodb_open_files = 3000 #innodb打开文件数
innodb_print_all_deadlocks = 1 #在error中打印锁信息
# others
memlock = 1 #MySQL是否使用交换分区
# replication
server-id = 1137 #server-id 搭建主从时必须配置且唯一
log-bin = /data/mysql/log/mysql-bin #二进制日志文件路径
#binlog-ignore-db=mysql #过滤mysql库的二进制日志
binlog_format = mixed #二进制日志模式 分三种,分别为:row,statement,mixed
expire_logs_days = 7 #删除过期日志时间
relay_log = /data/mysql/log/relay-bin #relay-log文件路径
#replicate_ignore_db = mysql #复制过滤MySQL库
#slave_skip_errors = 1062 #主从同步出现问题,从库忽略所有类型为1062的错误
log_slave_updates = 1 #级联复制使用的参数,为满足M-S-S
skip-slave-start #Slave不会随MySQL的启动而启动
#read_only = 1 #只读
sync_binlog = 1 #将binlog_cache中的数据强制写入磁盘
[mysqldump]
default-character-set = utf8 #数据库字符集