How to truncate MySQL table on boot,
but want make sure script execute after mysqld started
mysql -h localhost -u root -pPASSWORD DBNAME -e "truncate table tables"
谢谢。mysql在启动时截断表
How to truncate MySQL table on boot,
but want make sure script execute after mysqld started
mysql -h localhost -u root -pPASSWORD DBNAME -e "truncate table tables"
谢谢。mysql在启动时截断表
创建一个脚本startup.sql,将它存储在您的数据目录中,使其可读取到服务器。 startup.sql脚本包含您需要的语句,例如“TRUNCATE TABLE tables”。
以下行添加到您的my.cnf文件中的[mysqld]部分:
初始化文件= startup.sql
停止并重新启动服务器来测试。
相关文档可以在这里找到:http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_init-file
它的工作谢谢你。 – njai
取决于你为什么需要它截断......
或许可以考虑使用这将是“截断”服务器重新启动无论如何,因为它是只在内存中保存一个内存表...
否则yoou coud添加一行以截断每个需要截断到设置脚本的表,并确保脚本在启动时被调用。
在我的目的中,因为在mysql表中与iptables规则相关,如果存在于mysql表中,它不会创建新的iptables规则。那么如何启动脚本看起来像? – njai
把所有的truncate语句放在一个文本文件中(确保指定了schema.table,否则会破坏某些东西)。找到启动mysql的命令并添加--defaults-file =“path/to/your/file.txt”(如果已设置),那么我建议您将语句添加到此文件中。 –
什么操作系统? –
它在Debian上。 – njai