本教学使用环境介绍
伺服器端:Ubuntu 18.04 LTS
资料库:Mariadb 10.1.34(Mysql)
语言版本:php 7.3
本机端:MacOS High Sierraphp
网路上写的设定档是 /etc/mysql/my.cnf
但我实际去找是在 mariadb.conf.d 底下的 50-server.cnf 才是(多是 Mysql 跟 MariaDB 的差异?)html
$ cd /etc/mysql/mariadb.conf.d
使用 nano 开启mysql
$ nano 50-server.cnf
进入后会看到 [mysqld] ,直接在下面加上 slow_query 变成:sql
[mysqld] # 开启慢日志功能 slow_query_log = 1 # 查询时间超过 2 秒则定义为慢查询(可自行改秒数) long_query_time = 2 # 将产生的 slow query log 放到你指定的地方 slow_query_log_file = /var/www/slow_query.log
保存后别忘了重启资料库rest
systemctl restart mariadb.service
验证是否成功开启
先透过 CLI 进入 Mysql (Mariadb)日志
$ mysql -u root -p
进入后输入指令
如下 MariaDB [(none)]>
简称为 >
code
> show variables like '%quer%';
会出现如下表格server
+---------------------------------+--------------- ----------+ | Variable_name | Value | +---------------------------------+--------------- ----------+ | expensive_subquery_limit | 100 | | ft_query_expansion_limit | 20 | | have_query_cache | YES | | log_queries_not_using_indexes | OFF | | long_query_time | 2.000000 | | query_alloc_block_size | 16384 | | query_cache_limit | 1048576 | | query_cache_min_res_unit | 4096 | | query_cache_size | 16777216 | | query_cache_strip_comments | OFF | | query_cache_type | ON | | query_cache_wlock_invalidate | OFF | | query_prealloc_size | 24576 | | slow_query_log | ON | | slow_query_log_file | /var/www/slow_query.log | | wsrep_reject_queries | NONE | | wsrep_sst_donor_rejects_queries | OFF | +---------------------------------+--------------- ----------+
确认一下 Value
有无符合htm
slow_query_log 为 ON long_query_time 为刚刚设定的 2 秒 slow_query_log_file 为你刚刚指定的路径 /var/www/slow_query.log
符合表示已经设定成功,便可退出 MariaDB
ip
> exit;
参考资料:https://www.itread01.com/p/11...
Line ID:ianmacQQ:1258554508