MySQL database export and import and common error resolution
- 2020-05-30 21:12:02
- OfStack
MySQL command line export database:
1, enter the bin folder in the MySQL directory: the directory from cd MySQL to bin folder
As I typed the command line: cd C:\Program Files\MySQL\MySQL Server 4.1\bin
(or simply add the directory to windows's environment variable path)
2. Export database: mysqldump-u username -p database name
>
Exported file name
As I typed the command line: mysqldump-u root-p jluibmclub
>
d:\ jluibmclub.sql (this will allow you to enter your password into MySQL)
(if you export a single table, enter the table name after the database name.)
In the cmd command box, type C:/mysql/bin
>
mysqldump -uroot -p jluibmclub
>
d:\ jluibmclub .sql ;
Error message: mysqldump: Got error: 1049: Unknown database 'jluibmclub; 'when selecting the database, can't recognize jluibmclub database.
But here I am:
mysql
>
show databases;
Display:
+---------------+
| Database |
+---------------+
| jpa |
+---------------+
mysql
>
use jpa;
Display:
Database changed
The reason is simple, just remember one point. Not entering the mysql environment does not count as executing the sql statement, so there is no need to add a comma ("; ") after it. ).
If you enter mysql environment mysql
>
, then the input statement belongs to sql statement, and a comma ("; ") must be added at the end of the statement 1. ).
3. You will see that the file news.sql is automatically generated into the d diskette. If you do not specify the diskette, it will be in the bin directory by default.
Command line import database:
1, enter MySQL: mysql-u username -p
As I typed the command line: mysql-u root-p (enter the same and you will be asked to enter the MySQL password)
2. In MySQL-Front, create the new database you want to build. This is an empty database, such as create a new target database named news
3. Input: mysql
>
use target database name
As I typed the command line :mysql
>
use news;
4. Import file: mysql
>
File name imported by source;
As I type the command line: mysql
>
source news. sql(relative pathname if in bin, absolute directory name if in other directories);
MySQL backup and restore are done using the mysqldump, mysql, and source commands.
1. Backup and restore of MySQL under Win32