MySQL报错“MySQL server has gone away”的解决方法之一

    在RedHat Linux环境下,如果Mysql是默认安装以后,就没有修改过配置的话,那么在Mysql运行一段时间以后,使用它的应用程序可能出现“MySQL server has gone away”的错误。如Drupal网站,访问就可能出现这样的错误在界面上,但是可能部分页面访问又是正常的,这个问题在Mysql的官方网站上有说明,地址:http://dev.mysql.com/doc/refman/5.0/en/gone-away.html。

    这个时候就需要加大 my.cnf(Windows环境下是my.ini)文件中的max_allowed_packet的值(通常在默认值的基础上翻倍即可),如果文件中没有这个参数,那么直接添加这个参数的值就可以了。

    下面给出一个实际使用的例子(配置是否合理,性能如何,不同的应用场景和机器配置,这样的配置可能导致Mysql的性能有差异,这里提供的配置仅供参考):

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
innodb_flush_log_at_trx_commit=1
 
tmpdir = /tmp
thread_cache_size = 128
table_cache = 256
key_buffer = 64M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
max_allowed_packet = 1M
tmp_table_size=32M
max_heap_table_size=8045M
query_cache_size=128M
query_cache_type=1
long_query_time=2
innodb_buffer_pool_size = 8045M
innodb_additional_mem_pool_size = 8M
innodb_support_xa = 0
innodb_lock_wait_timeout = 50
innodb_flush_method=O_DIRECT
innodb_log_files_in_group = 2
innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
innodb_thread_concurrency = 8
lower_case_table_names = 1
key_buffer_size=384M
table_open_cache=512
interactive_timeout=315360000
wait_timeout=315360000
 
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
 

发表评论

邮箱地址不会被公开。 必填项已用*标注

机器人检查 *

分享我的最新文章标题到这里

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据