当前位置:网站首页>MySQL command line import and export data

MySQL command line import and export data

2022-06-10 23:55:00 Li_ XiaoJin

In refactoring the system , The original system used MySQL, Now we need to change to PostgreSQL, So you need to migrate the data . The current plan is to export the records of the production database , Import to a backup Library of the test environment , Then the program will convert the data into a new PostgreSQL database , Therefore, the production database export is involved , Because the production database cannot be used Navicat Other software connections , So you can only export from the command line , Make a note of .

export

This step does not require logging into the database , Use it directly mysqldumpl Command to export .

Export the entire library

mysqldump -u user name -p Database name > Exported file name

mysqldump -u root -p --databases db_name > test_db.sql

Export a table

mysqldump -u user name -p Database name Table name > Exported file name

Only export the database structure , Without data

mysqldump -u user name -p -d Database name > Exported file name

-d : Just back up the structure , Don't back up data . You can also use ”–no-data” Instead of ”-d”, The effect is the same .

example :

If appear -bash: mysqldump: command not found The error of , The processing is as follows :

find MySQL Installation path for ,

find / -name mysql -print

stay /usr/bin Create under directory mysqldump The soft links

My installation path here is /usr/local/mysql/bin/mysqldump ,

Carry out orders ln -fs /usr/local/mysql/bin/mysqldump /usr/bin/

After execution, you can use mysqldump The command .

Import

  1. Get into MySQL:mysql -u user name -p
  2. Create a new database , Or go to the database where you want to import data

Input :mysql>create database The name of the database to be created ;

Or input :mysql>use Database name to use ;

  1. Import files , Use source Command to import the file

Enter the command line :mysql>source / File path / file name .sql;

Today is the launch day of Shenzhou 12 , I wish Shenzhou 12 every success ! The three astronauts returned safely and triumphantly ! Pay tribute to China's Aerospace !

Hired Heroes , Breaking through the clouds and the sun !

End.

Copyright: use Creative Commons signature 4.0 International license agreement to license Links:https://lixj.fun/archives/mysql Command line export data

原网站

版权声明
本文为[Li_ XiaoJin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206102238038177.html