Common commands for MySQL database backup and Restoration

Source: Internet
Author: User
1. Check all usernames in mysql DATA: usemysql; selectdistinct (User) fromuser; 2. Run MySQL script in Linux: MySQL script in mysql: mysqlsourced: testss. sql4.MySQL to authorize others.

1. view all User names in mysql DATA: use mysql; select distinct (user) from User; 2. run the MySQL script in Linux: mysql source/opt/app/swiftsync/SQL/mysql/swiftsync_server. SQL 3. run the MySQL script in Windows: mysql sourced: \ test \ ss. SQL 4. other MySQL authorization

1. view all user names in mysql DATA:

Use mysql;

Select distinct (User) from user;

2. Run the MySQL script in Linux:

Mysql> source/opt/app/swiftsync/SQL/mysql/swiftsync_server. SQL

3. Run the MySQL script in Windows:

Mysql>Sourced: \ test \ ss. SQL

4. MySQL authorizes other machines to perform database training:

For exampleIf you want myuser to use mypassword to connect to the mysql server from any host.
Grant all privilegeson *. * TO 'myuser' @ '%' identified by 'mypassword' with grantoption;
If you want to allow myuser to connect to the mysql server from a host whose ip address is 192.168.1.3, and use mypassword as the password
Grant allprivileges on *. *'Root' @ '192. 168.1.3'Identified by 'mypassword' with grantoption;

Reference: http://www.blogjava.net/acooly/archive/2008/09/17/229368.html

5. view all users in mysql
Select user, host, password from mysql. user;

6. create databases, users, and authorized access

$ /usr/local/mysql/bin/mysql -u root -p>create database cheersdb;>create user 'cheers'@'localhost' identified by 'cheerspassword';>grant all privileges on cheersdb.* to 'cheers'@'localhost';

7. Backup and Restore MySQL database commands

Back up a single database

./Mysqldump-h localhost-u root-p Database Name>/opt/cheers/backup name. SQL

Back up the MySQL database in the format of a table with deletion

Backing up a MySQL database is in the format of a table with deletion, so that the backup can overwrite existing databases without the need to manually delete the original database.

Mysqldump -- add-drop-table-uusername-ppassword databasename> backupfile. SQL

Directly compress and back up the MySQL database

Mysqldump-hhostname-uusername-ppassword databasename | gzip> backupfile. SQL .gz

Back up a MySQL database table

Mysqldump-hhostname-uusername-ppassword databasenamespecific_table1 specific_table2> backupfile. SQL

Back up multiple MySQL databases at the same time

Mysqldump-hhostname-uusername-ppassword-databasesdatabasename1 databasename2 databasename3> multibackupfile. SQL

Back up database structures only

Mysqldump-no-data-databases databasename1 databasename2databasename3> structurebackupfile. SQL

Back up all databases on the server

Mysqldump-all-databases> allbackupfile. SQL

Command for restoring MySQL database

Mysql-h hostname-u username-p password databasename < p><>

Example: ./Mysql-h localhost-uroot-pswiftsync_i6

Swiftsync_i6The name of the database to be imported.

/Opt/app/db_backup/swiftsync_i5. SQLIs the name of the backup file.

Restore a compressed MySQL database

Gunzip <backupfile. SQL .gz | mysql-uusername-ppassword databasename

Transfer database to new server

Mysqldump-uusername-ppassword databasename | mysql-host = *. *-C databasename

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.