Home Database Mysql Tutorial 最简便的备份MySql数据库一些方法_MySQL

最简便的备份MySql数据库一些方法_MySQL

Jun 01, 2016 pm 02:12 PM
backup Export database method Table of contents


  使用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
3 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
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) May 04, 2024 pm 06:01 PM

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to set font size on mobile phone (easily adjust font size on mobile phone) How to set font size on mobile phone (easily adjust font size on mobile phone) May 07, 2024 pm 03:34 PM

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to choose a mobile phone screen protector to protect your mobile phone screen (several key points and tips for purchasing mobile phone screen protectors) How to choose a mobile phone screen protector to protect your mobile phone screen (several key points and tips for purchasing mobile phone screen protectors) May 07, 2024 pm 05:55 PM

Mobile phone film has become one of the indispensable accessories with the popularity of smartphones. To extend its service life, choose a suitable mobile phone film to protect the mobile phone screen. To help readers choose the most suitable mobile phone film for themselves, this article will introduce several key points and techniques for purchasing mobile phone film. Understand the materials and types of mobile phone films: PET film, TPU, etc. Mobile phone films are made of a variety of materials, including tempered glass. PET film is relatively soft, tempered glass film has good scratch resistance, and TPU has good shock-proof performance. It can be decided based on personal preference and needs when choosing. Consider the degree of screen protection. Different types of mobile phone films have different degrees of screen protection. PET film mainly plays an anti-scratch role, while tempered glass film has better drop resistance. You can choose to have better

An effective way to quickly remove age spots (teach you the skin care secrets to quickly and easily eliminate age spots) An effective way to quickly remove age spots (teach you the skin care secrets to quickly and easily eliminate age spots) May 03, 2024 pm 12:01 PM

Age spots are a common skin problem that tend to appear on the faces of older adults on exposed areas such as the neck and back of hands. It will also make people look older. It not only brings trouble to people's appearance. With the advancement of science and technology and the development of beauty technology, there are now many simple and quick ways to remove age spots, however. To restore young and healthy skin and help you eliminate age spots quickly, this article will share some effective skin care tips. 1. The importance of actively protecting the skin from ultraviolet damage, so it is very important to avoid prolonged exposure to the sun. Ultraviolet rays are one of the main causes of age spots. 2. Choose skin care products reasonably and use products containing antioxidants and whitening ingredients. Skin care products containing antioxidants and whitening ingredients can help reduce the appearance of age spots.

See all articles