MySQL Backup recovery under Linux

Source: Internet
Author: User
Tags mysql backup

For example, we want to back up a database named Linux that already exists in MySQL, using the command mysqldump
The command format is as follows:
[Email protected] root]# mysqldump-u root-p linux >/root/linux.sql
Enter Password: Enter the password for the database here

Through the above command, we have to understand two things, first back up the database is to be a database administrator backup, second: The backup destination is/root, the backup file name is Linux.sql. In fact, the location and file name of the backup, according to their own situation to decide. Filenames can be taken by themselves, the path can be arranged by themselves;
For example, I want to back up the Linux database to/home/beinan, the database file name is Linuxsir031130.sql, so you should enter the following command.

[[email protected] root] #mysqldump-u root-p Linux >/home/beinan/linuxsir031130.sql
Enter Password: Enter the database password for the database administrator root here

If the data volume conference takes up a lot of space, you can use gzip to compress the data, with the following command:

#mysqldump-U root-p TM | gzip > tm_050519.sql.gz


So we can find the backup file of MySQL database named Linux in the/home/beinan directory Linuxsir031130.sql
To sum up, we should learn to be flexible when learning.

Recovery:
First of all, we have to work on a few processes, such as adding a database administrator (if you haven't added a MySQL database administrator), creating a database, and so on.
For example, we want to/home/beinan this directory in the Linuxsir031130.sql this backup, import the database named Linux, should be the following operation;
[[email protected] root] #mysql-u root-p Linux Enter Password: Enter the password here

If the machine is good, the database is relatively small, a few minutes is good.




How do I export data from a database table? (different from backup OH)

#mysql

(#mysql >use Linux;) #可有可无

#mysql >select * from Linux.table-name to outfile "/home/table-name.txt";

#/home/table-name.txt may error, if this removes/home direct "Table-name.txt"

Saved in/var/lib/mysql/table-name.txt by default


A little supplement to the common commands of MySQL database;

A few common MySQL-related management commands
MySQL command: Basic text, display and use of MySQL database. The previous usage has been simply mentioned, such as login.
The Mysqladmin command, which is used to create and maintain MySQL database commands, has been briefly mentioned;
Isamchk is a database file that is used to repair, inspect, and optimize the. ISM suffix;
Mysqldump is used for backing up the database, which has been explained briefly before;
Myisamchk used to repair the. myi suffix of the database file;

For example, we want to check the database named Linux. myi database table If there is a problem, you should use the following command;

To stop the MYSQLD server.
[[email protected] root]#/opt/mysql/share/mysql.server stop

And then execute
[Email protected] root]#/opt/mysql/bin/myisamchk/opt/mysql/var/linux/*. MYI

The above command means checking all the. myi files, the directory of the database in the/opt/mysql/var/linux/directory

If there is a problem, you should use the-R parameter to fix
[Email protected] root]#/opt/mysql/bin/myisamchk-r/opt/mysql/var/linux/*. MYI

7]mysqlshow command: Displays the database and table selected by the user
[[email protected] root]#/opt/mysql/bin/mysqlshow-uroot-p [database name]

For example, I want to view a database named Linux;

[[email protected] root]#/opt/mysql/bin/mysqlshow-uroot-p Linux

MySQL Backup recovery under Linux

Related Article

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.