[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
MySQL 不会主动去创建日志文件,所以需要手动添加,添加完成后赋予所有用户可读可写权限,否则会报 premission denied
[root@iZm5e0rpsu8z9upjwrq5xgZ ~]# mkdir -p /usr/local/mysql/mysql-5.7.31/log [
root@iZm5e0rpsu8z9upjwrq5xgZ ~]# touch
/usr/local/mysql/mysql-5.7.31/log/general.log [root@iZm5e0rpsu8z9upjwrq5xgZ ~]#
touch /usr/local/mysql/mysql-5.7.31/log/slowqueries.log [
root@iZm5e0rpsu8z9upjwrq5xgZ ~]# cd /usr/local/mysql/mysql-5.7.31/log/ [
root@iZm5e0rpsu8z9upjwrq5xgZ log]# ls -a . .. general.log slowqueries.log [
root@iZm5e0rpsu8z9upjwrq5xgZ log]# ls -la 总用量 8 drwxr-xr-x 2 root root 4096 9月
25 16:26. drwxr-xr-x 3 root root 4096 9月 25 16:26 .. -rw-r--r-- 1 root root 0
9月 25 16:26 general.log -rw-r--r-- 1 root root 0 9月 25 16:26 slowqueries.log[
root@iZm5e0rpsu8z9upjwrq5xgZ log]# chmod 777 general.log [
root@iZm5e0rpsu8z9upjwrq5xgZ log]# chmod 777 slowqueries.log [
root@iZm5e0rpsu8z9upjwrq5xgZ log]# ls -la 总用量 8 drwxr-xr-x 2 root root 4096 9月
25 16:26. drwxr-xr-x 3 root root 4096 9月 25 16:26 .. -rwxrwxrwx 1 root root 0
9月 25 16:26 general.log -rwxrwxrwx 1 root root 0 9月 25 16:26 slowqueries.log[
root@iZm5e0rpsu8z9upjwrq5xgZ log]#
在 MySQL 配置文件(/etc/my.cnf)中写入:
# 开启通用日志 general_log=1 # 通用日志地址 general_log_file=
/usr/local/mysql/mysql-5.7.31/log/general.log# 开启慢查询日志 slow_query_log=1 #
慢查询日志地址 slow_query_log_file=/usr/local/mysql/mysql-5.7.31/log/slowqueries.log #
慢查询阀值 long_query_time=5 #
输出方式,FILE表示文件,TABLE表示数据库(可以在mysql库中看到日志),可以同时使用,方法如上,也可单独使用比如log_output='FILE',输出到文件比输出到数据库效率高
log_output='FILE,TABLE'
修改完成后重启 MySQL 服务:
service mysqld restart
使用如下命令打开 MySQL 日志文件,可以实时查看数据库的日志内容
tail -f /usr/local/mysql/mysql-5.7.31/log/general.log