Mysql useful commands

### Mysql dump ###


== Syntax global == 
mysqldump [options] db_name [tables]
== Syntax to backup only one database == 
mysqldump -u [username]  -p [password] [database_name] > [backup_file.sql]
== Syntax to backup multiple databases ==
mysqldump -u [username]  -p [password] –databases [database_names] > [backup_file.sql]
== Syntax to restore databases ==
mysqldump -u [username]  -p [password] [database_to_restore] < [backup_file.sql]
ex. [Only one database]
mysqldump -uroot -ppassword database_name > file_name
ex. [Multiple databases]
mysqldump -uroot -ppassword –databases database_name1 database_name2 > file_name
 
### Mysql like ###

ex. SELECT * FROM table_name
     WHERE colomn_name LIKE ‘%first_key%’ OR
                                     LIKE ‘%second_key%’
ex. SELECT * FROM table_name
     WHERE colomn_name REGEXP ‘first_key|second_key’
### Mysql rename table ###
RENAME TABLE table_name_before TO table_name_after
### Mysql update ###
ex. [update with only one id]
     UPDATE table_name
          SET field_name = ‘field_value’
          WHERE id_name = ‘id_value’
ex. [update with multiple ids]
     UPDATE table_name
          SET field_name = ‘field_value’
          WHERE id_name IN (1, 2, 3, 4, 5, 6)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s