简体   繁体   中英

mysql truncate table on boot

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"

thank you.

Create a script startup.sql, store it in your data directory, make it readable to the server. The startup.sql script contains the statements you need, for example "TRUNCATE TABLE tables;".

Add the following line to the [mysqld] section of your my.cnf file:

init-file=startup.sql

Stop and restart the server to test.

The relevant documentation can be found here: http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_init-file

depends on why you need it truncating...

perhaps consider using a memory table which would be 'truncated' on server restart anyway as it is only held in memory...

otherwise yoou coud add a line to truncate each table you need truncating to the set-up script and ensure that the script is called on startup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM