Knowledgebase

How to truncate MySQL database tables via SSH

To empty MySQL database tables through SSH, first you have to log in to your hosting account via SSH. Then you need to access the database which contains the table(s) that you want to truncate. To learn how to do it read the article on accessing MySQL databases via SSH. Once you do it you'll open the MySQL prompt which you can use to truncate the desired tables. Just type truncate table followed by the name of the table and press the Enter key on your keyboard:

mysql> truncate table table_name;

Of course, you have to replace table_name with the actual name of the table. Note that each command in the MySQL prompt ends with a semi-colon. The mysql> part in the beginning is there by default, so you don't have to type that. Let's say that you want to truncate a table called mg_logs. Then after you connect to the MySQL databases containing the table, you have to execute the following command:

mysql> truncate table mg_logs;

This will empty the table; it won't delete/drop the table itself. Truncating MySQL database tables can also be performed with phpMyAdmin. For more details check out the article on truncating database tables through phpMyAdmin.

Was this answer helpful?

 Print this Article

Also Read