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.