Skip to content

Useful mysql console commands

Michael Watts edited this page Jan 17, 2018 · 7 revisions

Logging in

mysql -u root -p

And enter password.

Dump a SQL file

mysqldump -u <user_name> -p <db_name> > /tmp/db_backup.sql

or dump with query

mysqldump -u <user_name> -p <database_name> --tables <table_name> --where="post_type = 'products' AND post_status = 'publish' AND guid LIKE '%http://www.hts-rds.fr%';" > dump.sql

Replace string in SQL file

sed -i -e 's/old-domain/new-domain/g' /tmp/db_backup.sql

you can use anything as a delimiter so for instance when using urls a comma could be used:

sed -i -e 's,http://old-domain,https://new-domain,g' /tmp/db_backup.sql

Import SQL file

mysql -u username -p database_name < file.sql

Wordpress

Update the siteurl and home rows in wp_options table

UPDATE wp_options
  SET option_value = "http://178.79.155.111"
  WHERE option_id = 1 OR option_id = 2;

View the siteurl and home rows in wp_options table

SELECT * 
  FROM wp_options 
  WHERE option_name = "siteurl"
  OR option_name = "home";

SSH

2 Best practices when logging in remotely to linux machine

WARGAMES

Clone this wiki locally