最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【已解决】Ubuntu中mysql然后开启error的log及配置中提示:Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf

MySQL crifan 51浏览 0评论
折腾:
【未解决】Ubuntu中mysql有时候会突然挂掉
期间,想要找到mysql偶尔挂掉的原因,希望找到error的log。
不过,看到配置
/etc/mysql/my.cnf
中error的log说是:
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
去看看
root@VM-158-80-ubuntu:/etc/mysql# cat /etc/mysql/conf.d/mysqld_safe_syslog.cnf
[mysqld_safe]
skip_log_error
syslog
Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
How and When To Enable MySQL Logs
其实是推荐做法
但是如果不想这样,那么可以去:
注释掉:
[mysqld_safe]
syslog
或直接删掉
/etc/mysql/conf.d/mysqld_safe_syslog.cnf
然后再去:
/etc/mysql/my.cnf
加上:
[mysqld_safe]
log_error=/var/log/mysql/mysql_error.log
 
[mysqld]
log_error=/var/log/mysql/mysql_error.log
即可。
Howto enable logs from MySQL configuration On Ubuntu | LAMPNODE | Focus On LAMP Technologies
debian中默认设置mysql的error的log,发送到syslog
去操作:
root@VM-158-80-ubuntu:/etc/mysql# cat /etc/mysql/conf.d/mysqld_safe_syslog.cnf
#[mysqld_safe]
#skip_log_error
#syslog

# cat /etc/mysql/my.cnf 
...
[mysqld_safe]
socket    = /var/run/mysqld/mysqld.sock
nice    = 0
log_error=/var/log/mysql/mysql_error.log
...
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
log_error=/var/log/mysql/mysql_error.log
...
重启mysql
service mysql restart
root@VM-158-80-ubuntu:/etc/mysql# service mysql status
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; bad; vendor preset: enabled)
   Active: active (running) since Fri 2019-06-07 22:03:45 CST; 3s ago
  Process: 4632 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
  Process: 4622 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 4631 (mysqld)
    Tasks: 28
   Memory: 161.0M
      CPU: 274ms
   CGroup: /system.slice/mysql.service
           └─4631 /usr/sbin/mysqld


Jun 07 22:03:42 VM-158-80-ubuntu systemd[1]: Starting MySQL Community Server...
Jun 07 22:03:45 VM-158-80-ubuntu systemd[1]: Started MySQL Community Server.
去看看log:
root@VM-158-80-ubuntu:/etc/mysql# ll /var/log/mysql
total 44
drwxr-s---  2 mysql adm     4096 Jun  7 22:03 ./
drwxrwxr-x 13 root  syslog  4096 Jun  7 06:25 ../
-rw-r-----  1 mysql adm    12476 Jun  7 13:39 mariadb-bin.000392
-rw-r-----  1 mysql adm      177 Jun  7 22:03 mariadb-bin.000393
-rw-r-----  1 mysql adm      154 Jun  7 22:03 mariadb-bin.000394
-rw-r-----  1 mysql adm      102 Jun  7 22:03 mariadb-bin.index
-rw-rw----  1 mysql adm       11 Aug 20  2018 mariadb-bin.state
-rw-r-----  1 mysql adm     3465 Jun  7 22:03 mysql_error.log
(此刻竟然)就有error_log了。
【总结】
Ubunt是基于Debian的。
Debian中mysql做法,默认是吧error的log发送到syslog中的
-》且mysql的配置文件
/etc/mysql/my.cnf
中也会有对应提示:
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
-》就不会有单独的error的log文件了。
-》想要单独有error的log文件,则去:
/etc/mysql/conf.d/mysqld_safe_syslog.cnf
中内容都注释掉:
#[mysqld_safe]
#skip_log_error
#syslog
/etc/mysql/my.cnf
加上error的log配置:
...
[mysqld_safe]
socket    = /var/run/mysqld/mysqld.sock
nice    = 0
log_error=/var/log/mysql/mysql_error.log
...

[mysqld]
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
log_error=/var/log/mysql/mysql_error.log
...
然后重启mysql
service mysql restart
即可看到对应log文件:
/var/log/mysql/mysql_error.log
了。

转载请注明:在路上 » 【已解决】Ubuntu中mysql然后开启error的log及配置中提示:Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
16 queries in 0.093 seconds, using 9.38MB memory