MySQL Database export table structure and data detailed

Source: Internet
Author: User


Export Database

--Export DBNAME table structure
mysqldump-uroot-p123456-d dbname > Dbname.sql

--Export dbname table data
Mysqldump-uroot-p123456-t dbname > Dbname.sql

--Export dbname table structure and data
mysqldump-uroot-p123456 dbname > Dbname.sql

To export a specified table in a database


--Export Test table structure under dbname

mysqldump-uroot-p123456-d dbname Test > Test.sql

--Export Test table data under dbname

Mysqldump-uroot-p123456-t dbname Test > Test.sql

--Export Test table structure and data under dbname

mysqldump-uroot-p123456 dbname Test > Test.sql

Restores

--Create a database

CREATE DATABASE dbname DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci;

--Restore Database

mysql-uroot-p123456 dbname </path/dbname.sql

--Restore Database

SOURCE Dbname.sql

--View table structure

Desc wp_users;
Show CREATE table Wp_users \g;

SELECT into outfile Export

SELECT * into outfile ' temp.txt '
FIELDS terminated by ', ' optionally enclosed by ' ' LINES terminated by ' \ n '
From table_name
WHERE Createtime < 1382716800;


LOAD DATA Import


LOAD DATA INFILE '/home/temp.txt '
INTO TABLE table_name
FIELDS terminated by ', ' optionally enclosed by ' ' LINES terminated by ' \ n '
(Product_id,uuid,mac,monitor,win_version,ip,createtime);

Note: Importing a remote server locally requires the load DATA local INFILE

Make sure that Local_infile is open and has permission to load data if it complains: Message:the used command isn't allowed with this MySQL version

1.MYSQL_CONNECT Specifies the fifth parameter 128 test, i.e. mysql_connect ($host, $user, $pwd, False, Client_local_files)
MySQL Extended version in 2.PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.