mysql的报错⽇志哪⾥看_mysql错误⽇志
### 错误⽇志是⾮常有⽤的东西,在上⼀篇 mysql字符集 中,因为看了⽹上很多博客,修改字符集的时候,在服务端` [mysqld]`下添加的变量内容为(博客⾥写的是这个变量,有很多博客都这样写,可能Mysql版本不⼀样吧):
```
default_character_set_server=utf8
```
### 结果在重启 Mysql的时候报错了,通过报错的信息⽆法判断到底哪⾥出了问题,够纠结的。。。
关键时刻只能靠错误⽇志了,那么错误⽇志在哪⾥呢?
### 查看错误⽇志⽂件位置(使⽤ SQL 语句),我这⾥显⽰的是⼀个相对路径,是在 /usr/local/mysql/data/ ⽬录下的,`terminal` 是主机名,默认以 `主机名.log` 的形式命名
```
mysql> show global variables like 'log_error';
+---------------+----------------+
| Variable_name | Value |
+---------------+----------------+
| log_error | ./ |
+---------------+----------------+
1 row in set (0.00 sec)
```
通过上⾯可以看到我的 Mysql错误⽇志在 /usr/local/mysql/data/ ⽬录下⾯,名字叫 `terminal.log`,来看看这家伙吧(这⾥我⾸先切换到了 root ⽤户,因为需要权限进⼊到 /usr/local/data/ ⽬录下):
```
[root@terminal data]#
2019-03-06T08:41:10.038619Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --
mysql下载starting the serverexplicit_defaults_for_timestamp server option (see documentation for more details).
2019-03-06T08:41:10.038695Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2019-03-06T08:41:10.038715Z 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.7.25) starting as process 9400 ...
2019-03-06T08:41:10.043950Z 0 [Note] InnoDB: PUNCH HOLE support available
2019-03-06T08:41:10.043973Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-03-06T08:41:10.043976Z 0 [Note] InnoDB: Uses event mutexes
2019-03-06T08:41:10.043978Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
2019-03-06T08:41:10.043980Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-03-06T08:41:10.043983Z 0 [Note] InnoDB: Using Linux native AIO
2019-03-06T08:41:10.044244Z 0 [Note] InnoDB: Number of pools: 1
2019-03-06T08:41:10.044368Z 0 [Note] InnoDB: Using CPU crc32 instructions
2019-03-06T08:41:10.045791Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-03-06T08:41:10.053211Z 0 [Note] InnoDB: Completed initialization of buffer pool
2019-03-06T08:41:10.055615Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-03-06T08:41:10.068979Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2019-03-06T08:41:10.077351Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-03-06T08:41:10.077449Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-03-06T08:41:10.194546Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-03-06T08:41:10.196823Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2019-03-06T08:41:10.196868Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2019-03-06T08:41:10.198591Z 0 [Note] InnoDB: Waiting for purge to start
2019-03-06T08:41:10.249588Z 0 [Note] InnoDB: 5.7.25 started; log sequence number 2524810
2019-03-06T08:41:10.250302Z 0 [Note] Plugin 'FEDERATED' is disabled.
2019-03-06T08:41:10.265156Z 0 [ERROR] unknown variable 'default_character_set_server=utf8'
2019-03-06T08:41:10.265192Z 0 [ERROR] Aborting
```
### 提⽰信息有很多类:Note、Warning、ERROR
我们需要看的是 ERROR,也就是最后两⾏,准确说我们要的信息在倒数第⼆⾏:
```
2019-03-06T08:41:10.265156Z 0 [ERROR] unknown variable 'default_character_set_server=utf8'
```
很明显,说 `default_character_set_server` 这个变量 Mysql不知道是什么玩意,回到上⼀篇的上⼀篇 mysql配置,查看可以在配置⽂件中定义的变量,使⽤ grep 搜索⼀个关键字吧:
```
[root@terminal data]# mysqld --verbose --help | grep character
2019-03-06T08:54:36.277849Z 0 [ERROR] unknown variable 'default_character_set_server=utf8'
--character-set-client-handshake
Don't ignore client side character set value sent during
(Defaults to on; use --skip-character-set-client-handshake to disable.)
--character-set-filesystem=name
Set the filesystem character set.
-C, --character-set-server=name
Set the default character set.
--character-sets-dir=name
Directory where character sets are
InnoDB Fulltext search maximum token size in characters
InnoDB Fulltext search minimum token size in characters
This characterizes the number of hits a hot block has to
characters
characteristics (isolation level, read only/read write,
character-set-client-handshake TRUE
character-set-filesystem binary
character-set-server latin1
character-sets-dir /usr/local/mysql/share/charsets/
2019-03-06T08:54:36.284286Z 0 [ERROR] Aborting
session-track-system-variables time_zone,autocommit,character_set_client,character_set_results,character_set_connection
```
### 嗯,确实没有 `default_character_set_server` 这玩意,到了 `character-set-server`,它的值和我们在 mysql查询的时候也⼀样,我在⽹上有看了⼀些博客,最终确认了就是这个变量,后⾯我修改了 `/etc/myf`,Mysql就可以启动了,从此我爱上了 错误⽇志,好东西
### 错误⽇志是有级别的,就像上⾯看到的 Note、Warning、ERROR 什么的,有时候我们只需要看 ERROR ,其他的信息占空间,不要查阅;了解⼀下错误⽇志级别?(错误⽇志级由 log\_warnings 变量决定)
```
mysql> show global variables like 'log_warnings';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_warnings | 2 |
+---------------+-------+
1 row in set (0.01 sec)
```
```
log_warnings 为0, 表⽰不记录告警信息。
log_warnings 为1, 表⽰告警信息写⼊错误⽇志。
log_warnings ⼤于1, 表⽰各类告警信息,例如有关⽹络故障的信息和重新连接信息写⼊错误⽇志。
```
### 我这⾥是 2,什么都显⽰,可以修改 log_warnings 的值来调整错误⽇志记录的内容
当然也不⼀定需要修改这个变量,有时候需要查看⽐较详细的错误信息,那么可以通过 gawk 来筛选出我们需要的错误信息,就像这样:
```
[root@terminal data]# | gawk '$3 == "[ERROR]" {print $0}'
2019-03-06T08:41:10.265156Z 0 [ERROR] unknown variable 'default_character_set_server=utf8' 2019-03-06T08:41:10.265192Z 0 [ERROR] Aborting
2019-03-06T09:05:18.048303Z 0 [ERROR] SSL error: Unable to get private key from 'server-key.pem' ```
可以看到还有⼀个 server-key.pem ⽂件问题,意思⼤概是⽆法获得这个⽂件的内容,看看这个⽂件吧:
```
[root@terminal data]# ll server-key.pem
-rw------- 1 root root 1679 3⽉ 5 16:27 server-key.pem
```
好像除了 root ⽤户,其他⼈都没有查看权限啊,给加⼀个查看权限吧:
```
[root@terminal data]# chmod +r server-key.pem
[root@terminal data]# ll server-key.pem
-rw-r--r-- 1 root root 1679 3⽉ 5 16:27 server-key.pem
```
加完权限之后可以把错误⽇志⽂件先清空⼀下(⽅便对⽐),然后在重启 Mysql服务,发现已经没那错误了,完美。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。