njai
njai

Reputation: 188

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.

Upvotes: 0

Views: 722

Answers (2)

Isotopp
Isotopp

Reputation: 3383

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

Upvotes: 1

Ian Wood
Ian Wood

Reputation: 6573

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.

Upvotes: 0

Related Questions