How to import/back up MYSQL databases using command lines in VPS

Source: Internet
Author: User

How to import/back up MYSQL databases using command lines in VPS

When using Linux VPS to build a website, if the database of the website is small, if I need to import the database to migrate the website or when other needs are required, phpmyadmin must be used to import and manage database files online. Today, when I was migrating a website, the database was more than MB. If I imported it online, I don't know how long it would take. In addition, I found that the maximum size of the online phpmyadmin database to be imported is 50 MB.

In this case, I will use the SSH command to import the database. If necessary, I will remember the following command:

Standard command: mysql-u database username-p Database Password Database Name <database file name. SQL

Example: mysql-ulaozuo -plaozuo.org laozuo <laozuo. SQL

Without explanation, you can see the comparison above.-u and-p are directly followed by no space between them and the user name and password. However, you must first download the laozuo. sqldatabase from the external directory and put it under the root directory of this website. Then the system automatically detects the import.

Similarly, how can we back up database files?

Standard command: mysqldump-u database username-p Database Password -- default-character-set = encoding Database Name> database file name. SQL

Example: mysqldump-ulaozuo -plaozuo.org -- default-character-set = gb2312 laozuo> laozuo. SQL

Two problems need to be noted here. The first one is the encoding problem. According to the encoding of your website database, whether it is gb2312 or UTF-8, and the database file name will be saved in the root directory of the website. Then we can download it through FTP or wget.

In this way, we can use the above import and backup databases to solve the large database websites. You can get twice the result with half the effort.

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.