How to backup and restore the mysql database if it is too large

How to backup and restore the mysql database if it is too large

Command: mysqlhotcopy

This command will lock the table before copying the file and synchronize the data to the data file to avoid copying incomplete data files. It is the safest and fastest backup method.

The command usage is:

mysqlhotcopy -u root -p<rootpass> db1 db2 … dbn <output_dir>

If you need to back up all databases, you can add the –regexp=”.*” parameter.

The MySQL hotcopy command can automatically lock data without shutting down the server during backup.

It also flushes the log so that the backup files and the log file checkpoints are kept in sync.

local:

1. Enter the bin folder under the MySQL directory: e: press Enter;

e:\>cd mysql\bin Enter

2. Export database: mysqldump -u username -p database name > exported file name

example:

mysqldump -uroot -p abc > abc.sql

(Export database abc to abc.sql file)

When prompted for a password, enter the password for the database username (if exporting a single table, enter the table name after the database name)

If a locktable error is prompted: leave a space after mysqldump -uroot -p abc and add --skip-lock-tables

3. Will you see the file news.sql automatically generated in the bin file?

Import the database using the MySQL command line:

1. Move the .sql file to be imported to the bin file. This path is more convenient.

2. Same as step 1 of the export above

3. Enter MySQL: mysql -u username -p

For example, the command line I entered is: mysql -u root -p?? (After entering the same, you will be asked to enter the MySQL password)

4. Create a new database in MySQL-Front. At this time, it is an empty database. For example, create a new target database named news.

5. Enter: mysql>use target database name

For example, the command line I entered is: mysql>use news;

6. Import file: mysql>source import file name;

For example, the command line I entered is: mysql>source news.sql;

MySQL backup and restore are both done using the mysqldump, mysql, and source commands.

1. Backup and restore of MySQL under Win32

1.1 Backup

Start menu | Run | cmd | Use the "cd \Program Files\MySQL\MySQL Server 5.0\bin" command to enter the bin folder | Use "mysqldump? -u username -p databasename >exportfilename" to export the database to a file, such as mysqldump -u root -p voice>voice.sql, and then enter the password to start exporting.

1.2 Restore

Enter MySQL Command Line Client, enter the password, enter "mysql>", enter the command " show databases; ", press Enter, and see what databases there are; create create database voice; ", press Enter; switch to the newly created database, enter " use voice; ", press Enter; import data, enter " source voice.sql; ", press Enter, start importing, and when "mysql>" appears again and there is no error prompt, the restoration is successful.

2. Backup and restore of MySQL under Linux

2.1 Backup

[root@localhost ~]# cd /var/lib/mysql (Enter the MySQL library directory and adjust the directory according to your MySQL installation)
[root@localhost mysql]# mysqldump -u root -p voice>voice.sql, enter the password.

2.2 Restore

Method 1:

[root@localhost ~]# mysql -u root -p Press Enter, enter the password, and enter the MySQL console "mysql>". Restore the same as 1.2.

Method 2:

[root@localhost ~]# cd /var/lib/mysql (Enter the MySQL library directory and adjust the directory according to your MySQL installation)
[root@localhost mysql]# mysql -u root -p voice<voice.sql, enter the password.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • How to implement scheduled backup of MySQL database
  • 8 ways to manually and automatically backup your MySQL database
  • Example of MySQL database backup function implemented by ThinkPHP framework
  • Navicat for MySQL scheduled database backup and data recovery details
  • Ideas and methods for incremental backup of MySQL database
  • Linux implements automatic and scheduled backup of MySQL database every day
  • Automatic backup of MySQL database using shell script
  • How to import and export MySQL database (backup and restore)
  • Mysql backup multiple database code examples

<<:  Learn Vue middleware pipeline in one article

>>:  The meaning and calculation method of QPS and TPS of MySQL database

Recommend

Docker container operation instructions summary and detailed explanation

1. Create and run a container docker run -it --rm...

Detailed explanation of Linux commands sort, uniq, tr tools

Sort Tool The Linux sort command is used to sort ...

Vue implements tree table

This article example shares the specific code of ...

Is it necessary to give alt attribute to img image tag?

Do you add an alt attribute to the img image tag? ...

Native JS to implement image carousel JS to implement small advertising plug-in

Recently I want to use native JS to implement som...

Common usage of regular expressions in Mysql

Common usage of Regexp in Mysql Fuzzy matching, c...

Detailed steps to modify MySQL stored procedures

Preface In actual development, business requireme...

Mybatis mysql delete in operation can only delete the first data method

Bugs As shown in the figure, I started to copy th...

HTML+CSS+JS sample code to imitate the brightness adjustment effect of win10

HTML+CSS+JS imitates win10 brightness adjustment ...

How to pass the value of the select drop-down box to the id to implement the code

The complete code is as follows : HTML code: Copy ...

10 HTML table-related tags

In fact many people will say “I’ve seen that table...

HTML tags list and usage instructions

List of HTML tags mark type Name or meaning effec...

Running PostgreSQL in Docker and recommending several connection tools

1 Introduction PostgreSQL is a free software obje...

A brief introduction to MySQL functions

Table of contents 1. Mathematical functions 2. St...