随着wordpress数据库越来越大,会发现网站越来越慢,现可以把wp_options表和wp_posts表里的一些无用数据删除,SQL语句如下:
DELETE FROM `mywp_posts` WHERE `post_title` = '自动草稿' OR `post_type` = 'revision'; DELETE FROM `mywp_options` WHERE `option_name` LIKE ('_transient_%');
你也可以使用mysql事件,这样就不用常常来执行上面的命令了,按照如下步骤即可:
#查看所有的mysql事件 SELECT * FROM mysql.event; #查看mysql定时事件是否打开
SHOW VARIABLES LIKE 'event_scheduler';
这种打开定时事件的方式在电脑重启或者mysql重启后会关闭,如果想长久打开可以设置my.ini或my.cnf,加入如下一行语句即可:
event_scheduler = ON
你如果会写事件SQL语句可以直接写好了运行下即可,不过还可以使用phpmyadmin或者那个啥工具来着设置,操作差不多,小编此处以phpmyadmin为例,看下图,不细说:
另附SQL语句:
CREATE DEFINER = `root`@`localhost` EVENT `delete_posts` ON SCHEDULE EVERY15 DAY STARTS '2019-04-24 00:00:00'ENDS '2020-02-20 00:00:00' ON COMPLETION PRESERVE ENABLE DO DELETE FROM `wp_posts` WHERE `post_title` = '自动草稿' OR `post_type` = 'revision'; CREATE DEFINER = `root`@`localhost` EVENT `delete_transient` ON SCHEDULE EVERY20 DAY STARTS '2019-04-24 00:00:00'ENDS '2020-02-20 00:00:00' ON COMPLETION PRESERVE ENABLE DO DELETE FROM `wp_options` WHERE `option_name` LIKE ( '_transient_%' );
然后,重启下mysql和运行下:
flush privileges;