Plum's Blog

MySQL 清错

工作接手一个服务器,原本上面跑什么东西和我没关系的,但是这玩意动不动内存爆炸让我很不理解。

于是今天好奇看了看错误,顺便把上面报的错误清除一下。

然而一开始就傻逼了,因为服务器不是我配的,我也不知道各组件配置文件在哪儿,只知道上面负载最重的是数据库,跑的 MySQL。

所以查询一下数据库的配置路径:

/usr/sbin/mysqld --verbose --help | grep -A 1 'Default options'

看到:

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf 

基本可以确定配置文件路径了,然后在这里面发现了一条警告:

超时时间你设定 10 年是闹哪样啊,内存不爆炸就鬼了啊,改回默认的 8 小时先看看算了,等需要再继续缩短。

配置文件里找到 wait_timeout 进行修改。

然后处于强迫症把其他的警告问题也一个一个的消除一下:

160622  8:33:16 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.

正如错误所说,key_buffer 设置已经被 key_buffer_size 取代了,所以在配置文件里修改替换

160622  8:33:16 [Warning] Changed limits: max_open_files: 1024  max_connections: 214  table_cache: 400

默认的配置文件的最大连接数是很不科学的,而最大文件打开数是不需要设置的, MySQL 会根据最大连接数以及表 Cache 自动计算最大文件打开数。

官网所说计算公式是: max_open_files= max(max(wanted_files, max_connections*5)

所以因为服务器也比较强力,根据公式进行了修改,稍微写的大了点。

160622  8:33:16 [Warning] Can't create test file /var/lib/mysql/root.lower-test
160622  8:33:16 [Warning] Can't create test file /var/lib/mysql/root.lower-test
/usr/sbin/mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 13)

发现是目录权限问题,用 chmod 或者其他方式都可以解决, 777 也可以 然后关闭非主机以外的远程连接也可以。

/usr/sbin/mysqld: File '/var/log/mysql/mysql-bin.~rec~' not found (Errcode: 13)
160622  8:33:16 [ERROR] MYSQL_BIN_LOG::open_purge_index_file failed to open register  file.
160622  8:33:16 [ERROR] MYSQL_BIN_LOG::open_index_file failed to sync the index file.

日志的问题在显示系统的 error.log 的时候看到了详细的信息:

 [Warning] Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. CREATE... IGNORE SELECT is unsafe because the order in which rows are retrieved by the SELECT determines which (if any) rows are ignored. This order cannot be predicted and may differ on master and the slave. 

解决方法有二,一个是照着标准改 SQL 一个是改 binlog_format 为 MIXED。

当然前者我是不会去做的。

编辑配置文件修改:

binlog_format = MIXED

最后重新加载配置

service mysql reload

检查没有报错了,其他都是小问题,主要是内存再也不会爆炸了,又可以上班安心划水了。

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »