Performance optimization of mysql5.6.10

Use the following command when testing the configure script:

rm -rf  /var/log/mysqld.log

/usr/local/mysql/bin/mysqld_safe --log-error=/var/log/mysqld.log

vi /var/log/mysqld.log

Then check /var/log/mysqld.log to see why mysql did not start normally.

 

 

vi /etc/my.cnf

Under the [mysqld] configuration section add:

 
[mysqld]

#The port number when the myslqd service is running
port=3306

The #socket file is unique in the Linux environment, and the user's client software connection can directly use unix socket to connect to Mysql without going through the TCP/IP network.
socket=/tmp/mysql.sock

#Avoid Mysql's external locking, reduce the chance of errors, and enhance stability.
skip-external-locking

#Forbid MySql to perform DNS resolution on external connections. Using this option can eliminate the time for MySQL to perform NDS resolution. However, it should be noted that if this option is enabled, all remote host
connection authorizations must use the IP address method, otherwise MYSQL will not be able to process connection requests normally.
skip-name-resolve

The value of the #back_log parameter indicates how many requests can be stored in the pair stack in a short period of time before MySQL temporarily stops responding to new requests. If the system has many connections in a short period of time, you need to increase the value of this parameter. The parameter value specifies the size of the listening queue for incoming TCP/IP connections. Different operating systems have their own limits on the size of this queue. If you try to set back_log higher than the limit of the operating system, it will be invalid. The default value is 50. For LINUX systems, it is recommended to set it to less than 512. Integer.
back_log=384

#Index buffer size. Increasing it can get better index processing performance. For servers with about 4GB of memory, this parameter can be set to 256M or 384M. If the parameter value is set too large, it will reduce the overall efficiency of the server.
key_buffer_size=384M

#Set the maximum value of a message transmission in network transmission. The default value of the system is 1MB, and the maximum value is 1GB. It must be set to a multiple of 1024, and the unit is bytes.
max_allowed_packet=4M

#Set the stack size of each thread of MySQL, the default value is large enough to satisfy common operations. The range that can be set is 128KB to 4GB, and the default is 192K.
thread_stack=256k


#Set the buffer size that can be used when query sorting. The default size of the system is 2MB. Starting from version 5.1.23, it can be limited to 4GB on 64-bit platforms other than WINDOWS. The allocation corresponding to this parameter
is inherently exclusive to each connection. If there are 100 connections, then the actual allocated total sorting buffer size is 100*6=600MB, then for a server with a memory of about 4GB, it is recommended to set it. 6MB-8MB.
sort_buffer_size=6M

#读查询操作所能使用的缓冲区大小,和sort_buffer_size一样,该参数对应的分配内在也是每个连接独享。
read_buffer_size=4M


#设置Thread Cache池中可以缓存的连接池线程最大数量,可设置为0-16384,默认为0。1GB内存我们配置为8,2GB内存我们配置为16,4GB或4GB以上内在我们配置为64。
thread_cache_size=64
#指定Mysql查询缓冲区的大小,可以通过在Mysql控制台观察,如果Qcache_lowmem_prunes的值非常大,则表明经常出现缓冲不够的情况,如果
Qcache_hits的值非常大,则表明查询缓冲使用的非常频繁
query_cache_size=64M

#设置内在临时表最大值,如果超过该值,则会将临时表写入磁盘,其范围为1KB至4GB。
tmp_table_size=256M

#指定MYSQL允许的最大连接进程数,如果在访问程序时经常出现TOO MANY CONNECTIONS的错误提示,则需要增大该参数值。
max_connections=5000


#指定一个请求的最大连接时间,对于4GB左右内在的服务器来说,可以将其设置为5-10
wait_timeout=120

#该参数取值为服务器逻辑CPU数量*2,比如,服务器有两个物理CPU,每个物理CPU支持HT超线程,所以实际取值4*2=8,这也是目前双四核主流
服务器的配置。
thread_concurrency=8

#开启该选项可以彻底关闭MYSQL的TCP/IP连接方式,如果WEB服务器是以远程连接的方式访问MYSQL的数据库服务器,则不要开启该选项,否则>将无法正常连接。
skip-networking


innodb_flush_log_at_trx_commit
#抱怨Innodb比MyISAM慢 100倍?那么你大概是忘了调整这个值。默认值1的意思是每一次事务提交或事务外的指令都需要把日志写入(flush)
硬盘,这是很费时的。特别是使用电池供电缓存(Battery backed up cache)时。设成2对于很多运用,特别是从MyISAM表转过来的是可以的>,它的意思是不写入硬盘而是写入系统缓存。日志仍然会每秒flush到硬 盘,所以你一般不会丢失超过1-2秒的更新。设成0会更快一点,但安>全方面比较差,即使MySQL挂了也可能会丢失事务的数据。而值2只会在整个操作系统 挂了时才可能丢数据。
innodb_flush_log_at_trx_commit=2

#这是 InnoDB 存储引擎的事务日志所使用的缓冲区。类似于 Binlog Buffer,InnoDB 在写事务日志的时候,为了提高性能,也是先将信息写>入 Innofb Log Buffer 中,当满足 innodb_flush_log_trx_commit 参数所设置的相应条件(或者日志缓冲区写满)之后,才会将日志写到文>件(或者同步到磁盘)中。可以通过 innodb_log_buffer_size 参数设置其可以使用的最大内存空间。
innodb_log_buffer_size=2M

#这个数字要根据实际的情况来设定,但对于大多数的情况,是一个比较合适的设置
innodb_thread_concurrency=8

#tmp_table_size 的默认大小是 32M。如果一张临时表超出该大小,MySQL产生一个 The table tbl_name is full 形式的错误,如果你做很多
高级 GROUP BY 查询,增加 tmp_table_size 值。
tmp_table_size=64M

#随机读取数据缓冲区使用内存(read_rnd_buffer_size):和顺序读取相对应,当 MySQL 进行非顺序读取(随机读取)数据块的时候,会利用>这个缓冲区暂存读取的数据。如根据索引信息读取表数据,根据排序后的结果集与表进行Join等等。总的来说,就是当数据块的读取需要满足>一定的顺序的情况下,MySQL 就需要产生随机读取,进而使用到 read_rnd_buffer_size 参数所设置的内存缓冲区。
read_rnd_buffer_size=16M

#你最好在定义数据库命名规则的时候就全部采用小写字母加下划线的组合,而不使用任何的大写字母。
lower_case_table_names=1

#设置校验模式
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


#默认配置没开查询缓存哦亲
explicit_defaults_for_timestamp

 

功能:

#关闭MYSQL日志

 
执行:
/usr/local/mysql/bin/mysql -u root -p
输入密码,登陆到mysql,然后执行
reset master;
退出后执行:
vi /etc/my.cnf
查找
log-bin=mysql-bin binlog_format=mixed
再这两行前面加上#,将其注释掉,再执行重启mysql命令
这样就关闭了mysql日志了
/etc/init.d/mysql restart
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326746614&siteId=291194637