Today, a student asked me if I could migrate the database. I thought I should have to re-create the table, but it is too inefficient and I still need to import many records from the table, so I thought that mysql bin provided two commands, mysqldump and resource.
Mysql Command LineExport Database:
1. Run the command to enter the bin directory of the mysql installation directory. For example, run the command cd C: \ Program Files \ MySQL Server 5.5 \ bin.
(If it is Windows 7 and mysql is installed in the C directory, if the above command prompts that access is denied, it is enough to run the command prompt as an administrator)
2.Export Database: Mysqldump-u username-p Database Name> exported file name
For example, if the command line I entered is mysqldump-u root-p atm> atm. SQL (after entering the command, you will be asked to enter the MySQL password)
(If you export a single table, enter the table name after the database name)
3. After executing the preceding command, we can see the exported atm. SQL database file in the bin directory, which contains all the tables and records in the database.
Mysql command line import database:
1. First, we will import the. SQL file to the database and put it in the bin directory, which is convenient.
2. Go to MySQL Command Line Client, enter the password, go to "mysql>", and create a new database (mysql> create database test ;)
3. use the newly created database mysql> use test;
4. Import file: the file name imported from mysql> source. For example, I want to import the exported atm. SQL data file: mysql> source atm. SQL;
5. If no error message is displayed, run the show tables command. You can see that the content in the newly created test database has been imported into the atm database.