Home Database Mysql Tutorial MySQL心得8-1-使用客户端程序备份和恢复_MySQL

MySQL心得8-1-使用客户端程序备份和恢复_MySQL

Jun 01, 2016 pm 01:41 PM
client program Computer hardware

bitsCN.com MySQL心得8-1-使用客户端程序备份和恢复 1. 备份和恢复需求分析 数据库中的数据丢失或被破坏可能是由于以下原因: (1)计算机硬件故障。由于使用不当或产品质量等原因,计算机硬件可能会出现故障,不能使用。如硬盘损坏会使得存储于其上的数据丢失。 (2)软件故障。由于软件设计上的失误或用户使用的不当,软件系统可能会误操作数据引起数据破坏。 (3)病毒。破坏性病毒会破坏系统软件、硬件和数据。 (4)误操作。如用户误使用了诸如DELETE、UPDATE等命令而引起数据丢失或破坏。 (5)自然灾害。如火灾、洪水或地震等,它们会造成极大的破坏,会毁坏计算机系统及其数据。 (6)盗窃。一些重要数据可能会遭窃。     因此,必须制作数据库的复本,即进行数据库备份,在数据库遭到破坏时能够修复数据库,即进行数据库恢复,数据库恢复就是把数据库从错误状态恢复到某一正确状态。 备份和恢复数据库也可以用于其他目的,如可以通过备份与恢复将数据库从一个服务器移动或复制到另一个服务器。 2.  数据恢复的手段 有多种可能会导致数据表的丢失或者服务器的崩溃,一个简单的DROP TABLE或者DROP DATABASE的语句,就会让数据表化为乌有。更危险的是DELETE *FROM table_name,可以轻易地清空数据表,而这样的错误是很容易发生的。 因此,拥有能够恢复的数据对于一个数据库系统来说是非常重要的。MySQL有三种保证数据安全的方法。 (1)数据库备份:通过导出数据或者表文件的拷贝来保护数据。 (2)二进制日志文件:保存更新数据的所有语句。 (3)数据库复制:MySQL内部复制功能建立在两个或两个以上服务器之间,通过设定它们之间的主从关系来实现的。其中一个作为主服务器,其他的作为从服务器。在此主要介绍前两种方法。 数据库恢复就是当数据库出现故障时,将备份的数据库加载到系统,从而使数据库恢复到备份时的正确状态。 恢复是与备份相对应的系统维护和管理操作,系统进行恢复操作时,先执行一些系统安全性的检查,包括检查所要恢复的数据库是否存在、数据库是否变化及数据库文件是否兼容等,然后根据所采用的数据库备份类型采取相应的恢复措施。 3.  使用客户端程序备份和恢复 MySQL提供了很多免费的客户端程序和实用工具,不同的MySQL客户端程序可以连接服务器以访问数据库或执行不同的管理任务。这些程序不与服务器进行通信,但可以执行MySQL相关的操作。在MySQL目录下的BIN子目录中存储着这些客户端程序。 这里简单介绍一下mysqldump程序和mysqlimport程序。使用客户端的方法:打开DOS终端,进入BIN目录,路径为:C:/Program Files/MySQL/MySQLServer 5.1/bin,后面介绍的客户端命令都在此处输入,     1).  使用mysqldump备份数据 mysqldump客户端也可用于备份数据,它比SQL语句多做的工作是可以在导出的文件中包含表结构的SQL语句,因此可以备份数据库表的结构,而且可以备份一个数据库,甚至整个数据库系统。 (1_1)备份表 命令格式:mysqldump[options] db_name [tables] > filename 说明:options是mysqldump命令支持的选项,可以通过执行mysqldump -help命令得到mysqldump选项表及帮助信息,这里不详细列出。db_name是数据库名,后面可以跟需要备份的表名。Filename为最后备份的文件名,如果该语句中有多个表,则都保存在这个文件中,文件默认的保存地址是MySQL的bin目录下。如果要保存在特定位置,可以指定其具体路径。注意,文件名在目录中不能已经存在,否则新的备份文件将会将原文件覆盖,造成不必要的麻烦。 同其他客户端程序一样,备份数据时需要使用一个用户账号连接到服务器,这需要用户手工提供参数或在选项文件中修改有关值。参数格式为:-h[hostname] -u[username] -p[password] 其中,-h后是主机名,-u后是用户名,-p是用户密码,-p选项和密码之间不能有空格。 例: 使用mysqldump备份XS表和KC表。具体命令如下: mysqldump -h localhost -u root -p123456XSCJ XS KC > twotables.sql 说明:如果是本地服务器,-h选项可以省略。在MySQL的bin目录下可以看到,已经保存了一个.sql格式的文件,文件中存储了创建XS表和KC表的一系列SQL语句。 注意:若在命令中没有表名,则备份整个数据库。 (1_2)备份数据库 mysqldump程序还可以将一个或多个数据库备份到一个文件中。 命令格式: mysqldump [options] --databases DB1[DB2 DB3...] > filename 例: 备份XSCJ数据库和mysql数据库到D盘FILE文件夹下。 命令如下: mysqldump -uroot -p123456 --databases XSCJmysql>D:/FILE/data.sql 说明:命令执行完后,在FILE文件夹下的data.sql文件被创建了,其中存储了XSCJ数据库和mysql数据库的全部SQL语句。     mysql还能备份整个数据库系统,即系统中的所有数据库。 例:备份MySQL服务器上的所有数据库。使用如下命令: mysqldump -uroot -p123456--all-databases>all.sql 虽然用mysqldump导出表的结构很有用,但是在恢复数据时,如果数据量很大,众多SQL语句将使恢复的效率降低。可以通过使用--tab=选项,分开数据和创建表的SQL语句。--tab=选项会在选项中“=”后面指定的目录里,分别创建存储数据内容的.txt格式文件和包含创建表结构的SQL语句的.sql格式文件。该选项不能与--databases或--all-databases同时使用,并且mysqldump必须运行在服务器主机上。 例: 将XSCJ数据库中所有表的表结构和数据都分别备份到D盘FILE文件夹下。命令如下: mysqldump -uroot -p123456 --tab=D:/FILE/  XSCJ 其效果是在目录FILE中生成6个文件,分别是xs.txt、xs.sql、kc.txt、kc.sql、xs_kc.txt和xs_kc.sql。 (1_3)恢复数据库 mysqldump程序备份的文件中存储的是SQL语句的集合,用户可以将这些语句还原到服务器中以恢复一个损坏的数据库。 例:假设XSCJ数据库损坏,用备份文件将其恢复。 备份XSCJ数据库的命令为: mysqldump -uroot -p123456 XSCJ>XSCJ.sql 恢复命令为: mysql -uroot -p123456 XSCJ  作者 tianyazaiheruan bitsCN.com

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
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)

How to make Google Maps the default map in iPhone How to make Google Maps the default map in iPhone Apr 17, 2024 pm 07:34 PM

The default map on the iPhone is Maps, Apple's proprietary geolocation provider. Although the map is getting better, it doesn't work well outside the United States. It has nothing to offer compared to Google Maps. In this article, we discuss the feasible steps to use Google Maps to become the default map on your iPhone. How to Make Google Maps the Default Map in iPhone Setting Google Maps as the default map app on your phone is easier than you think. Follow the steps below – Prerequisite steps – You must have Gmail installed on your phone. Step 1 – Open the AppStore. Step 2 – Search for “Gmail”. Step 3 – Click next to Gmail app

VMware Horizon Client cannot be opened [Fix] VMware Horizon Client cannot be opened [Fix] Feb 19, 2024 pm 11:21 PM

VMware Horizon Client helps you access virtual desktops conveniently. However, sometimes the virtual desktop infrastructure may experience startup issues. This article discusses the solutions you can take when the VMware Horizon client fails to start successfully. Why won't my VMware Horizon client open? When configuring VDI, if the VMWareHorizon client is not open, an error may occur. Please confirm that your IT administrator has provided the correct URL and credentials. If everything is fine, follow the solutions mentioned in this guide to resolve the issue. Fix VMWareHorizon Client Not Opening If VMW is not opening on your Windows computer

How to sort photos by face on Windows 10 and 11 How to sort photos by face on Windows 10 and 11 Aug 08, 2023 pm 10:41 PM

The operation of Windows is getting better and better with every version, with attractive features to improve the user experience. One feature users will want to explore on Windows 10 and 11 is the ability to sort photos by faces. This feature allows you to group photos of friends and family using facial recognition. Sounds fun, right? Read on to learn how to take advantage of this feature. Can I group photos by faces on Windows? Yes, you can use the Photos app to group pictures by faces on Windows 10 and 11. However, this feature is not available on the Photos app version. Additionally, you can link these photos to contacts using the People tab. Therefore, using this function you can

VMware Horizon client freezes or stalls while connecting [Fix] VMware Horizon client freezes or stalls while connecting [Fix] Mar 03, 2024 am 09:37 AM

When connecting to a VDI using the VMWareHorizon client, we may encounter situations where the application freezes during authentication or the connection blocks. This article will explore this issue and provide ways to resolve this situation. When the VMWareHorizon client experiences freezing or connection issues, there are a few things you can do to resolve the issue. Fix VMWareHorizon client freezes or gets stuck while connecting If VMWareHorizon client freezes or fails to connect on Windows 11/10, do the below mentioned solutions: Check network connection Restart Horizon client Check Horizon server status Clear client cache Fix Ho

How to write a simple countdown program in C++? How to write a simple countdown program in C++? Nov 03, 2023 pm 01:39 PM

C++ is a widely used programming language that is very convenient and practical in writing countdown programs. Countdown program is a common application that can provide us with very precise time calculation and countdown functions. This article will introduce how to use C++ to write a simple countdown program. The key to implementing a countdown program is to use a timer to calculate the passage of time. In C++, we can use the functions in the time.h header file to implement the timer function. The following is the code for a simple countdown program

Clock app missing in iPhone: How to fix it Clock app missing in iPhone: How to fix it May 03, 2024 pm 09:19 PM

Is the clock app missing from your phone? The date and time will still appear on your iPhone's status bar. However, without the Clock app, you won’t be able to use world clock, stopwatch, alarm clock, and many other features. Therefore, fixing missing clock app should be at the top of your to-do list. These solutions can help you resolve this issue. Fix 1 – Place the Clock App If you mistakenly removed the Clock app from your home screen, you can put the Clock app back in its place. Step 1 – Unlock your iPhone and start swiping to the left until you reach the App Library page. Step 2 – Next, search for “clock” in the search box. Step 3 – When you see “Clock” below in the search results, press and hold it and

How to open a website using Task Scheduler How to open a website using Task Scheduler Oct 02, 2023 pm 11:13 PM

Do you frequently visit the same website at about the same time every day? This can lead to spending a lot of time with multiple browser tabs open and cluttering the browser while performing daily tasks. Well, how about opening it without having to launch the browser manually? It's very simple and doesn't require you to download any third-party apps, as shown below. How do I set up Task Scheduler to open a website? Press the key, type Task Scheduler in the search box, and then click Open. Windows On the right sidebar, click on the Create Basic Task option. In the Name field, enter the name of the website you want to open and click Next. Next, under Triggers, click Time Frequency and click Next. Select how long you want the event to repeat and click Next. Select enable

iOS 17: How to organize iMessage apps in Messages iOS 17: How to organize iMessage apps in Messages Sep 18, 2023 pm 05:25 PM

In iOS 17, Apple not only added several new messaging features, but also tweaked the design of the Messages app to give it a cleaner look. All iMessage apps and tools, such as the camera and photo options, can now be accessed by tapping the "+" button above the keyboard and to the left of the text input field. Clicking the "+" button brings up a menu column with a default order of options. Starting from the top, there's camera, photos, stickers, cash (if available), audio, and location. At the very bottom is a "More" button, which when tapped will reveal any other installed messaging apps (you can also swipe up to reveal this hidden list). How to reorganize your iMessage app You can do this below

See all articles