Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to import and export sql files by mysql

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Mysql how to import and export sql files, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Under window

1. Export the entire database

Mysqldump-u user name-p database name > exported file name

Mysqldump-u dbuser-p dbname > dbname.sql

two。 Export a table

Mysqldump-u user name-p database name table name > exported file name

Mysqldump-u dbuser-p dbname users > dbname_users.sql

3. Export a database structure

Mysqldump-u dbuser-p-d-- add-drop-table dbname > d:/dbname_db.sql

-d No data-- add-drop-table adds a drop table before each create statement

4. Import database

Common source commands

Go to the mysql database console, such as

Mysql-u root-p

Mysql > use database

Then use the source command, followed by a script file (such as .sql used here)

Mysql > source d:/dbname.sql

5. Import data into the database

Mysql-uroot-D database name

1. Import data into a table in the database

Mysql-uroot-D database name table name

D:\ APMServ5.2.6\ MySQL5.1\ bin > mysqldump-u root-p erp lightinthebox_tags > ligh

Tinthebox.sql

Under linux

1. Export the database using the mysqldump command (pay attention to the installation path of mysql, that is, the path of this command):

1. Export data and table structure:

Mysqldump-u user name-p password database name > database name. Sql

# / usr/local/mysql/bin/ mysqldump-uroot-p abc > abc.sql

When you hit enter, you will be prompted to enter the password.

2. Export only the table structure

Mysqldump-u user name-p password-d database name > database name. Sql

# / usr/local/mysql/bin/ mysqldump-uroot-p-d abc > abc.sql

Note: / usr/local/mysql/bin/-> data directory of mysql

Second, import the database

1. First build an empty database

Mysql > create database abc

2. Import the database

Method 1:

(1) Select a database

Mysql > use abc

(2) set database coding

Mysql > set names utf8

(3) Import data (note the path of the sql file)

Mysql > source / home/abc/abc.sql

Method 2:

Mysql-u user name-p password database name < database name. sql

# mysql-uabc_f-p abc < abc.sql

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report