mysql import and export the entire library, or import or export the sql file of a table

Import library

    mysql -h127.0.0.1 -u用户名 -p密码 数据库名 < sqlFileName.sql
eg :mysql -h127.0.0.1 -uname -p database_name < sqlFileName.sql

How to use the command:

     mysql: Use the mysql command

     -h: Followed by the ip you want to import: the local is either 127.0.0.1 or localhost, or the ip address that can be accessed by the remote public network

     -u mysql username: generally we install the default root, the password is either 123 or 123456 that is -uroot

     -p here is the password, you don't need to write it. After the entire command is entered, press Enter to see where the password is entered. After entering the password, press Enter to import

     database_name: database name, which database you want to import data into

    < Fixed writing

    sqlFileName.sql is the name of the sql file you want to import (this sql file can be the entire library or the sql statement of a table)

****** If you are using a linux server, remember not to log in to mysql to proceed .

--在使用的时候先登录mysql,清空该数据库具体语句
show database; //查看所有的数据库
drop database shops; //删库
create database shops; //创建库

eg: Import command under linux

mysql -h127.0.0.1 -uroot -p shops < /data/server/shops.sql

eg: import command under windows

Note: I want to import data to the shops library of 127.0.0.1 on this machine. My mysql username is root and the password is not filled in. The corresponding imported sql is cms_tag.sql under the current path (the path of the sql file is based on your own path. enter).

Then press Enter and you will see the prompt to enter the password: copy the assigned password shift+insert to the password (you can't see the entered password), and then press Enter. The system will automatically execute the import of sql statements

❤1. Import the structure and data of a table (you can export the corresponding table structure and data when exporting directly in sqlFile)

   mysql -h127.0.0.1 -uroot -p databasename < sqlFile.sql
eg:mysql -h127.0.0.1 -uroot -p my_new_project < cms_tag.sql
-- 回车输入密码

 

Export library

mysqldump  -umj -p -h 127.0.0.1  databasename >newfile.sql;

How to use the command:

     mysqldump: Use mysql export commands

     -h  is followed by the ip you want to import: local is either 127.0.0.1 or localhost

     -u mysql username: generally we install the default root, the password is either 123 or 123456 that is -uroot

     -p here is the password, you don't need to write it. After the entire command is entered, press Enter to see where the password is entered. After entering the password, press Enter to import

     database_name: database name, which database you want to import data into

    >  Fixed writing

    sqlFileName.sql is the name of the sql file you want to export

Other import methods

    ❤1. Export the structure of a table (test) in the database database dbname


      mysqldump -u用户名 -p密码 -d dbname test>db.sql;
  eg: mysqldump -uroot -p -d shop goods>goods.sql; 
   --回车输入密码

    ❤2. Export all table structure and table data of database dbname (without -d)

    mysqldump -u用户名 -p密码  dbname >db.sql;
eg:mysqldump -uroot -p  shop >db.sql;
   --回车输入密码

    ❤3. Export the database to a certain table (test) structure and table data of dbname (without -d)

    mysqldump -u用户名 -p密码 dbname test>db.sql;
eg: mysqldump -uroot -p shop test>test.sql;
   --回车输入密码

  ❤4. The structure and table data of multiple tables (test1, test2, test3) of dbname in the exported data are separated by spaces

    mysqldump -u用户名 -p密码 dbname test1 test2 test3>db.sql;
eg: mysqldump -uroot -p shop test1 test2 test3>db.sql;
   --回车输入密码

   ❤5. Export all user libraries under root (the export location is under your current path)

   mysqldump -uroot -p --all-databases > sqlAllFile.sql
eg:mysqldump -uroot -p --all-databases > sqlAllFile.sql
-- 回车输入密码

Note: Two minus signs (--) in front of all, and a minus sign (-) in front of databases --all-databases

Guess you like

Origin blog.csdn.net/www1056481167/article/details/108049671