Home > Database > Mysql Tutorial > body text

mysql导入导出命令_MySQL

WBOY
Release: 2016-06-01 13:46:06
Original
761 people have browsed it

bitsCN.com

用mysqldump和source

 
可以使用这种方式导出数据:
mysqldump -urott -P5678 --default-character-set=gb2312 -p -h127.0.0.1 Test test1 > test1.sql
也可以这样:
mysql -uroot -P5678 --default-character-set=gb2312 -p -h127.0.0.1 -e "select * from Test.test1" > test1.sql    (不过这样要手动建表,当然可以 show create test1得到建表语句)
导入:
可以这样(在mysql命令行下)
mysql>use Test;
mysql>source test1.sql;
如果用select的方式得到的文件,应该这样导入:
mysql>load data infile "test.sql" into table Test.test1;

 
导入时可以"show processlistG"查看导入状态。

 
有时候会发生错误:ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`Test/test1`, CONSTRAINT `xxx` FOREIGN KEY (`AA`) REFERENCES `BB` (`AA`))
这时需要对外键约束进行删除,比如:
alter table cwealinfo drop foreign key `xxx`;

 
也可以:set foreign_key_checks = 0;

 
导出和导入时需要注意数据库的版本,比如从4导到5,最好用4的mysqldump,否则可能会失败。另外还需要注意字符集问题,如果两个库的字符集不同,可能会导致问题,因此导入前最好用“show variables like %char%”查看下是否需要调整字符集设置。

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!