Small tips about mysql and ssh

A quick reminder on how to connect to database mysql and clear the table in console ssh.

In console, connecting to mysql:

mysql -u *database_user* -p

then, select database

USE *database_name*;

and see all table

SHOW TABLES;

If you need to list all tables by size:

SELECT 
    TABLE_NAME AS 'Table Name',
    ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024, 2) AS 'Size (MB)'
FROM 
    information_schema.TABLES
WHERE 
    TABLE_SCHEMA = 'database_name'
ORDER BY 
    (DATA_LENGTH + INDEX_LENGTH) DESC;

And finally, clear the tables:

TRUNCATE TABLE *table_name*;

After all, exit:

EXIT;

 

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
The comment language code.