How to Use the command line to export data to the MySQL database in LNMP: lnmpmysql

Source: Internet
Author: User
Tags mysql commands import database

How to Use the command line to export data to the MySQL database in LNMP: lnmpmysql

As site or server O & M personnel, website backup and restoration operations must be skillful. MySQL database export and import operations are essential. For general users, you may use visual operation interfaces such as phpMyAdmin, however, this kind of interface operations often encounter errors when the database is large.

If you are familiar with Linux commands and use vps or ECS, you can use MySQL commands to export and import databases, which is very convenient and efficient!

Export Database

Export the database to the db_wp. SQL .gz file:

Mysqldump-u database username-p Database Password -- add-drop-table -- complete-insert database name | gzip> db_wp. SQL .gz

Please note that, based on your actual situation, modify the above "Database User Name", "Database Password", and "Database Name" as specific values. Generally, the "database username" should use the root with the highest permission. The database password should be the password of the root user.

Import Database

Because the exported database is gz compressed, We need to decompress it before import:

gzip -d db_wp.sql.gz

The extracted file is db_wp. SQL and then imported to the database:

Mysql-u database username-p Database Password Database Name <db_wp. SQL -- default-character-set = utf8

Mysql error server has gone away

During the operation, the mysql server has gone away error may occur, which is caused by a large database, insufficient cache, or operation timeout. You can modify the mysql configuration to solve the problem:

1. Open the configuration file (this shows the configuration file under the lnmp of June, if your path is not this one, find it by yourself)

vi /etc/my.cnf

2. Find the wait_timeout and interactive_timeout variables and set the value

wait_timeout=2880000interactive_timeout = 2880000

If you do not have these two parameters, simply add them.

3. Find max_allowed_packet and add the value of this variable, such as 100 M (you can also set the size you need)

max_allowed_packet = 100M

The max_allowed_packet parameter is used to control the maximum length of the Communication buffer.

Of course, other parameters can be adjusted as needed:

4. Restart the mysql service.

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.