`

mysql导出导入

阅读更多
linux下dump导出例子:
mysqldump -u 用户名 -p 数据库名 > /xxx/yyy/zzz.sql;


linuxdump导入例子:
mysql -h hostName -u 用户名 -p密码 -D数据库名 < xxx.sql  --default-character-set=utf8
如果要执行的sql中包含 procedure 的 创建语句,则因为 procudure 中语句的分隔符和用来分隔 sql 语句的 sql delimiter 都是 ;,发生冲突,所以需要在 create procedure 语句前将 sql delimiter 设置为其他的符号以避免这种冲突(之后再设置回 ;)。如下:
drop procedure if exists recommendation;
delimiter //
create PROCEDURE recommendation ()
BEGIN
-- 含有符号 ; 的 procedure 定义语句
END//
delimiter ;


load csv data to a table:
mysql> load data local infile 'uniq.csv' into table tblUniq fields terminated by ','
enclosed by '"'
lines terminated by '\n'
(uniqName, uniqCity, uniqComments)



Using ”select ... into outfile“ export data to csv file:
mysql> select visitor_id, visitable_id
INTO OUTFILE '/home/xxx/user-browsing.csv'
	FIELDS TERMINATED BY ','
	LINES TERMINATED BY '\n'
from visited_users
where visitable_type = 'User';



另外两个导入命令:
source 
\. 



MySQL Databases Tutoria - How to Backup and Restore (Export and Import):
http://www.mydigitallife.info/2007/07/21/how-to-backup-and-restore-export-and-import-mysql-databases-tutorial/
引用


phpMyAdmin can be used to export or backup MySQL databases easily. However, if the database size is very big, it probably won’t be a good idea. phpMyAdmin allows users to save database dump as file or display on screen, which involves exporting SQL statements from the server, and transmitting the data across slower network connection or Internet to user’s computer. This process slow the exporting process, increase database locking time and thus MySQL unavailability, slow the server and may simply crash the Apache HTTPD server if too many incoming web connections hogging the system’s resources.

The better way to backup and export MySQL database is by doing the task locally on the server, so that the tables’ data can be instantly dumped on the local disk without delay. Thus export speed will be faster and reduce the time MySQL database or table is locked for accessing. This tutorial is the guide on how to backup (export) and restore (import) MySQL database(s) on the database server itself by using the mysqldump and mysql utilities. There are basically two methods to backup MySQL, one is by copying all table files (*.frm, *.MYD, and *.MYI files) or by using mysqlhotcopy utility, but it only works for MyISAM tables. Below tutorial will concentrate on mysqldump which works for both MyISAM and InnoDB tables.

How to Export or Backup or Dump A MySQL Database

To export a MySQL database into a dump file, simply type the following command syntax in the shell. You can use Telnet or SSH to remotely login to the machine if you don’t have access to the physical box.

mysqldump -u username -ppassword database_name > dump.sql


Replace username with a valid MySQL user ID, password with the valid password for the user (IMPORTANT: no space after -p and the password, else mysqldump will prompt you for password yet will treat the password as database name, so the backup will fail) and database_name with the actual name of the database you want to export. Finally, you can put whatever name you like for the output SQL dump file, here been dump.sql.

The while data, tables, structures and database of database_name will be backed up into a SQL text file named dump.sql with the above command.

How to Export A MySQL Database Structures Only

If you no longer need the data inside the database’s tables (unlikely), simply add –no-data switch to export only the tables’ structures. For example, the syntax is:

mysqldump -u username -ppassword –no-data database_name > dump.sql


How to Backup Only Data of a MySQL Database

If you only want the data to be backed up, use –no-create-info option. With this setting, the dump will not re-create the database, tables, fields, and other structures when importing. Use this only if you pretty sure that you have a duplicate databases with same structure, where you only need to refresh the data.

mysqldump -u username -ppassword –no-create-info database_name > dump.sql


How to Dump Several MySQL Databases into Text File

–databases option allows you to specify more than 1 database. Example syntax:

mysqldump -u username -ppassword –databases db_name1 [db_name2 ...] > dump.sql


How to Dump All Databases in MySQL Server

To dump all databases, use the –all-databases option, and no databases’ name need to be specified anymore.

mysqldump -u username -ppassword –all-databases > dump.sql


How to Online Backup InnoDB Tables

Backup the database inevitable cause MySQL server unavailable to applications because when exporting, all tables acquired a global read lock using FLUSH TABLES WITH READ LOCK at the beginning of the dump until finish. So although READ statements can proceed, all INSERT, UPDATE and DELETE statements will have to queue due to locked tables, as if MySQL is down or stalled. If you’re using InnoDB, –single-transaction is the way to minimize this locking time duration to almost non-existent as if performing an online backup. It works by reading the binary log coordinates as soon as the lock has been acquired, and lock is then immediately released.

Syntax:

mysqldump -u username -ppassword –all-databases –single-transaction > dump.sql


How to Restore and Import MySQL Database

You can restore from phpMyAdmin, using Import tab. For faster way, upload the dump file to the MySQL server, and use the following command to import the databases back into the MySQL server.

mysql -u username -ppassword database_name < dump.sql


The import and export of MySQL database not only is important to recover the data when disaster strikes, but also provides an easy way to migrate or move to another server, such as when switching web hosting providers. However, do note that one common problem – character set encoding. Newer release of mysqldump uses UTF8 as its default charset if nothing is specified, while older versions (older than 4.1 typically) use Latin1 as default characterset. If you database charset is Latin1 and dump in UTF8 collation, the data may ends up become simply rubbish, garbled, or unreadable (frequently happen with Wordpress blog). If this case, use –default-character-set=charset_name option to specify the character set or convert the database to UTF8.




使用phpMysqlAdmin导出/导入图解教程:
http://www.siteground.com/tutorials/php-mysql/mysql_export.htm
分享到:
评论

相关推荐

    MySQL导出导入命令的用例

    ### MySQL导出导入命令的用例 在数据库管理与维护工作中,经常需要对MySQL数据库进行备份或迁移操作。本文将详细介绍如何使用`mysqldump`工具来完成这些任务,并结合给定文件中的示例进行具体说明。 #### 1. 导出...

    MySQL导出导入命令的用例.rar

    MySQL是世界上最受欢迎的关系型数据库管理系统...通过学习和实践这些MySQL导出和导入的命令用例,您可以更有效地管理数据库,确保数据的安全性和可用性。在实际操作中,应根据具体需求和环境调整参数,以实现最佳效果。

    mysql导出导入命令

    ### MySQL导出与导入命令详解 #### 一、MySQL导出命令详解 ##### 1. 导出整个数据库 在日常的数据库管理工作中,我们常常需要将整个数据库的数据及结构导出为一个备份文件,以备不时之需。常用的导出命令格式如下...

    MySQL导出导入命令的用例 _数据库技巧

    ### MySQL导出与导入命令详解 #### 一、导出整个数据库 在进行数据库备份或迁移时,常常需要将整个数据库导出为SQL文件。这可以通过`mysqldump`命令来实现。以下是一个示例命令: ```sql mysqldump -u用户名 -p ...

    解决navcat>mysql导出导入乱码问题

    通过以上步骤和知识点,你应该能有效地解决Navicat与MySQL之间的导出导入乱码问题。在实际操作中,务必细心检查每个环节,确保字符集的一致性,这样才能保证数据迁移的准确性和完整性。如果问题依然存在,可能需要...

    MySQL导出数据并通过sqlldr导入oracle

    同时代码还会生成sqlldr命令需要用到的control文件和bat文件,以及连接Oracle的配置文件,只要将MySQL导出的数据文件合到一起,执行bat文件,即可完成数据导入到Oracle的任务。所有文件都是以导入导出的那张表的表名...

    MYSQL 数据库导入导出命令

    MYSQL 数据库导入导出命令 MySQL 数据库导入导出命令是数据库管理员和开发者经常使用的命令,用于将 MySQL 数据库导出到文件中,以便备份、还原或迁移到其他服务器。下面将详细介绍 MySQL 数据库导入导出的命令和...

    mysql导出导入中文表解决方法

    在开发过程中会经常用到mysql导出导入中文表,本文将详细介绍其如何使用,需要的朋友可以参考下一、先针对utf8导出: (1)导出源数据库的所有表: 代码如下: mysqldump -u root -p密码 –socket=mysql.sock –default-...

    java调用mysql命令 导入导出数据库

    在Java编程中,调用MySQL命令来导入和导出数据库是一种常见的操作,这涉及到数据库管理、数据迁移或者备份恢复等场景。在这个过程中,Java通过JDBC(Java Database Connectivity)接口与MySQL进行交互,利用MySQL...

    MySQL数据导入导出

    在数据库管理和维护中,数据导入和导出是非常关键的操作,尤其是在MySQL数据库管理系统中。数据导入导出的目的多种多样,比如数据备份、数据迁移、数据整合等,因此掌握高效可靠的数据导入导出方法对于数据库管理员...

    mysql数据导入导出

    ### MySQL 数据导入与导出详解 #### 一、MySQL 数据导出 MySQL 提供了多种方式来导出数据,其中最常用的就是 `mysqldump` 命令。通过这个命令,用户可以灵活地导出整个数据库或者指定的表。 ##### 1. 导出整个...

    MySQL数据导入与导出

    ### MySQL数据导入与导出详解 在数据库管理与维护中,数据的导入与导出是一项基本而重要的操作,尤其在MySQL这种广泛使用的数据库系统中。本文将深入探讨MySQL数据导入与导出的方法,通过实际案例解析,帮助读者...

    mysql导入导出到excel

    实现将数据库与excel之间数据的导入导出

    mysql命令行导入导出

    在MySQL数据库管理中,命令行工具提供了一种高效的方式来导入和导出数据,这对于备份、迁移或在不同环境间同步数据至关重要。当我们处理中文字符时,可能会遇到乱码问题,这是因为字符编码不一致导致的。本文将深入...

    mysql数据导入导出php版 mysql数据导入导出php版

    MySQL数据库在Web开发中扮演着核心角色,而PHP作为服务器端脚本语言,常常用于处理与MySQL相关的数据操作,包括数据的导入和导出。在本文中,我们将深入探讨如何使用PHP来实现MySQL数据的导入与导出,以及这一过程中...

    MYSQL专用导入导出工具mysql-front

    MySQL-Front是一款专为MySQL设计的图形用户界面(GUI)工具,它提供了便捷的方式来管理和操作数据库,包括导入和导出数据。下面将详细介绍MySQL-Front在MySQL数据库管理中的作用和使用方法。 首先,MySQL-Front提供...

    导入导出mysql数据

    知识点:MySQL 数据库的导入与导出操作及 Java 实现 在 IT 行业中,数据库的管理和维护是一项至关重要的工作。特别是在 MySQL 这样的流行关系型数据库管理系统中,数据的备份与恢复变得尤为重要。本篇文章将深入...

    MySQL.zip_mysql导入_mysql导出

    在标题“MySQL.zip_mysql导入_mysql导出”中,提到的是使用压缩文件(ZIP)进行MySQL数据库的数据导入和导出操作。相比于直接使用MySQL客户端工具,这种方法可能提供更快的速度。这通常涉及到将数据库的结构和内容...

Global site tag (gtag.js) - Google Analytics