Home Database Mysql Tutorial 网上提供的最简便的MySql数据库备份的方法

网上提供的最简便的MySql数据库备份的方法

Jun 07, 2016 pm 05:59 PM

网上提供的最简便的MySql数据库备份的方法

使用MYSQL进行数据库备份,又很正规的数据库备份方法,同其他的数据库服务器有相同的概念,但有没有想过,MySQL会有更简捷的使用文件目录的备份方法,而且又快有好。
  
  一、数据备份捷径
  因为这个方法没有得到官方正式文档的验证,我们暂称为试验吧。
  
  目的:备份hostA主机中一个mysql数据库TestA,并恢复到到hostB机中
  
  试验环境:
  
  操作系统:WinNT4.0,Mysql3.22.34,phpMyAdmin 2.1.0
  
  在hostA中安装mysql数据库并建立TestA数据库
  
  hostB机安装mysql数据库,没有TestA数据库
  
  方法步骤:
  
  启动phpMyAdmin察看HostA和HostB中的数据库列表,在HostB中没有TestA数据库
  
  找到HostA中mysql的安装目录,并找到数据库目录data
  
  在我的试验环境中,这个目录是
  
  C:mysqldata
  
  找到对应数据库名称的子目录
  
  C:mysqldataTestA
  
  粘贴拷贝到HostB的Data目录下,是HostA同HostB Mysql数据目录下的文件相同
  
  刷新HostB的phpMyAdmin察看一下数据库列表,我们看到TestA已经出现,并且作查询修改等操作都正常,备份恢复恢复成功
  
  试验结论:Mysql的数据库可以通过文件形式保存,备份,恢复只要将相应文件目录恢复即可,无需使用其它工具备份。
  
  二、正规的方法(官方建议):
  导出要用到MySQL的mysqldump工具,基本用法是:
  
  mysqldump [OPTIONS] database [tables]
  
  如果你不给定任何表,整个数据库将被导出。
  
  通过执行mysqldump --help,你能得到你mysqldump的版本支持的选项表。
  
  注意,如果你运行mysqldump没有--quick或--opt选项,mysqldump将在导出结果前装载整个结果集到内存中,如果你正在导出一个大的数据库,这将可能是一个问题。
  
  mysqldump支持下列选项:
  
  --add-locks
  
  在每个表导出之前增加LOCK TABLES并且之后UNLOCK TABLE。(为了使得更快地插入到MySQL)。
  
  --add-drop-table
  
  在每个create语句之前增加一个drop table。
  
  --allow-keywords
  
  允许创建是关键词的列名字。这由在列名前面加表名的方法做到。
  
  -c, --complete-insert
  
  使用完整的insert语句(用列名字)。
  
  -C, --compress
  
  如果客户和服务器均支持压缩,压缩两者间所有的信息。
  
  --delayed
  
  用INSERT DELAYED命令插入行。
  
  -e, --extended-insert
  
  使用全新多行INSERT语法。(给出更紧缩并且更快的插入语句)
  
  -#, --debug[=option_string]
  
  跟踪程序的使用(为了调试)。
  
  --help
  
  显示一条帮助消息并且退出。
  
  --fields-terminated-by=...
  
  --fields-enclosed-by=...
  
  --fields-optionally-enclosed-by=...
  
  --fields-escaped-by=...
  
  --fields-terminated-by=...
  
  这些选择与-T选择一起使用,并且有相应的LOAD DATA INFILE子句相同的含义。
  
  LOAD DATA INFILE语法。
  
  -F, --flush-logs
  
  在开始导出前,洗掉在MySQL服务器中的日志文件。
  
  -f, --force,
  
  即使我们在一个表导出期间得到一个SQL错误,继续。
  
  -h, --host=..
  
  从命名的主机上的MySQL服务器导出数据。缺省主机是localhost。
  
  -l, --lock-tables.
  
  为开始导出锁定所有表。
  
  -t, --no-create-info
  
  不写入表创建信息(CREATE TABLE语句)
  
  -d, --no-data
  
  不写入表的任何行信息。如果你只想得到一个表的结构的导出,这是很有用的!
  
  --opt
  
  同--quick --add-drop-table --add-locks --extended-insert --lock-tables。
  
  应该给你为读入一个MySQL服务器的尽可能最快的导出。
  
  -pyour_pass, --password[=your_pass]
  
  与服务器连接时使用的口令。如果你不指定“=your_pass”部分,mysqldump需要来自终端的口令。
  
  -P port_num, --port=port_num
  
  与一台主机连接时使用的TCP/IP端口号。(这用于连接到localhost以外的主机,因为它使用 Unix套接字。)
  
  -q, --quick
  
  不缓冲查询,直接导出至stdout;使用mysql_use_result()做它。
  
  -S /path/to/socket, --socket=/path/to/socket
  
  与localhost连接时(它是缺省主机)使用的套接字文件。
  
  -T, --tab=path-to-some-directory
  
  对于每个给定的表,创建一个table_name.sql文件,它包含SQL CREATE 命令,和一个table_name.txt文件,它包含数据。 注意:这只有在mysqldump运行在mysqld守护进程运行的同一台机器上的时候才工作。.txt文件的格式根据--fields-xxx和--lines--xxx选项来定。
  
  -u user_name, --user=user_name
  
  与服务器连接时,MySQL使用的用户名。缺省值是你的Unix登录名。
  
  -O var=option, --set-variable var=option
  
  设置一个变量的值。可能的变量被列在下面。
  
  -v, --verbose
  
  冗长模式。打印出程序所做的更多的信息。
  
  -V, --version
  
  打印版本信息并且退出。
  
  -w, --where='where-condition'
  
  只导出被选择了的记录;注意引号是强制的!
  
  "--where=user='jimf'" "-wuserid>1" "-wuserid  
  最常见的mysqldump使用可能制作整个数据库的一个备份:
  
  mysqldump --opt database > backup-file.sql
  
  但是它对用来自于一个数据库的信息充实另外一个MySQL数据库也是有用的:
  
  mysqldump --opt database   mysql --host=remote-host -C database
  
  由于mysqldump导出的是完整的SQL语句,所以用mysql客户程序很容易就能把数据导入了:
  
  mysqladmin create target_db_name
  
  mysql target_db_name
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Explain the role of InnoDB redo logs and undo logs. Explain the role of InnoDB redo logs and undo logs. Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

How does MySQL index cardinality affect query performance? How does MySQL index cardinality affect query performance? Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL for Beginners: Getting Started with Database Management MySQL for Beginners: Getting Started with Database Management Apr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

MySQL vs. Other Databases: Comparing the Options MySQL vs. Other Databases: Comparing the Options Apr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

Explain the InnoDB Buffer Pool and its importance for performance. Explain the InnoDB Buffer Pool and its importance for performance. Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL: Structured Data and Relational Databases MySQL: Structured Data and Relational Databases Apr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

See all articles