mysql数据库备份及恢复命令 mysqldump,source的用法_MySQL
mysql数据库备份及恢复命令 mysqldump,source的用法_MySQL
还原一个数据库:
mysql -h localhost -u root -p123456 www<c:/www.sql
备份一个数据库:
mysqldump -h localhost -u root -p123456 www > d:/www2008-2-26.sql
//以下是在程序中进行测试
//$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile"; $command="mysqldump -h localhost -u root -p123456 guestbook > guestbook2-29.sql"; system($command); echo "success";
************************************************
备份MySQL数据库的命令
mysqldump -hhostname -uusername -ppassword databasename > backupfile.sql
备份MySQL数据库为带删除表的格式
备份MySQL数据库为带删除表的格式,能够让该备份覆盖已有数据库而不需要手动删除原有数据库。
mysqldump - add-drop-table -uusername -ppassword databasename > backupfile.sql
直接将MySQL数据库压缩备份
mysqldump -hhostname -uusername -ppassword databasename | gzip > backupfile.sql.gz
备份MySQL数据库某个(些)表
mysqldump -hhostname -uusername -ppassword databasename specific_table1 specific_table2 > backupfile.sql
同时备份多个MySQL数据库
mysqldump -hhostname -uusername -ppassword –databases databasename1 databasename2 databasename3 > multibackupfile.sql
仅仅备份数据库结构
mysqldump –no-data –databases databasename1 databasename2 databasename3 > structurebackupfile.sql
备份服务器上所有数据库
mysqldump –all-databases > allbackupfile.sql
还原MySQL数据库的命令
mysql -hhostname -uusername -ppassword databasename < backupfile.sql
还原压缩的MySQL数据库
gunzip < backupfile.sql.gz | mysql -uusername -ppassword databasename
将数据库转移到新服务器
mysqldump -uusername -ppassword databasename | mysql –host=*.*.*.* -C databasename
几个常用用例:
1.导出整个数据库
mysqldump -u 用户名 -p 数据库名 > 导出的文件名 mysqldump -u root -p dataname >dataname.sql
这个时候会提示要你输入root用户名的密码,输入密码后dataname数据库就成功备份在mysql/bin/目录中.
2.导出一个表
mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名 mysqldump -u root -p dataname users> dataname_users.sql
3.导出一个数据库结构
mysqldump -u wcnc -p -d –add-drop-table smgp_apps_wcnc >d:\wcnc_db.sql -d 没有数据 –add-drop-table 在每个create语句之前增加一个drop table
4.导入数据库
常用source 命令
进入mysql数据库控制台,
如
mysql -u root -p
mysql>use 数据库
然后使用source命令,后面参数为脚本文件(如这里用到的.sql)
mysql>source d:\wcnc_db.sql
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<1″
最常见的mysqldump使用可能制作整个数据库的一个备份:
mysqldump –opt database > backup-file.sql
但是它对用来自于一个数据库的信息充实另外一个MySQL数据库也是有用的:
mysqldump –opt database | mysql –host=remote-host -C database
由于mysqldump导出的是完整的SQL语句,所以用mysql客户程序很容易就能把数据导入了:
shell> mysqladmin create target_db_name shell> mysql target_db_name < backup-file.sql
就是
shell> mysql 库名 < 文件名
以上就是mysql数据库备份及恢复命令 mysqldump,source的用法_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

I believe that many friends are accustomed to using SourceInsight to read and analyze source code under Windows. There are indeed more efficient tools under LINUX, but it is troublesome and cumbersome to configure them. I believe many people definitely hope to be able to use them under Linux. SourceInsight can be used. The following editor will give you a detailed explanation of the use of SourceInsight in Ubuntu! Let’s go and see it together! This is my system information: Linuxgavin-laptop2.6.32-40-generic#87-UbuntuSMPTueMar600:56:56UTC2012x86_64GNU/Li

Source is the button to switch the input signal source or select a different input source. Typically found on televisions, projectors, sound systems, computer monitors, and other equipment. On the TV, the source button allows users to switch between different input sources to play different content on the TV. On a projector, the source button has a similar function and can connect different devices to the projector. On the audio system, the source button is used to switch between different audio input sources. On computer monitors, the source button functions similarly to TVs and projectors, etc.

PHP and PDO: How to perform database backup and restore operations When developing web applications, database backup and restore are very important tasks. As a popular server-side scripting language, PHP provides a wealth of libraries and extensions, among which PDO (PHP Data Objects) is a powerful database access abstraction layer. This article will introduce how to use PHP and PDO to perform database backup and restore operations. Step 1: Connect to the database Before actual operation, we need to establish a connection to the database. Use PDO pair

In the process of developing business systems, the database is a very important part. Therefore, backing up and restoring the database is a very necessary operation. This article will combine examples of the ThinkPHP6 framework to introduce how to use ThinkPHP6 to implement database backup and recovery. 1. Database backup 1.1 Environment preparation Before performing database backup, you need to confirm the following points: 1. You need to set the bin directory address of the mysql database and add its path to the system Path variable; 2. Mysqld needs to be installed

With the rapid development of the Internet, large-scale MySQL database backup and recovery has become one of the essential skills for major enterprises and websites. With the widespread application of Memcached, how to back up and restore Memcached has also become an important issue. As one of the main languages for web development, PHP has unique advantages and skills in handling backup and recovery of MySQL and Memcached. This article will introduce in detail the implementation method of PHP processing MySQL and Memcached backup and recovery.

In the current Internet era, the importance of data is self-evident. As one of the core components of Internet applications, database backup and recovery work is particularly important. However, as the amount of data continues to increase and business requirements become increasingly complex, traditional database backup and recovery solutions can no longer meet the high availability and high performance requirements of modern applications. Therefore, optimizing the backup and recovery performance of MySQL database has become an urgent problem that needs to be solved. In practice, we have adopted a series of project experiences to effectively improve MySQL data

Title: Using ThinkORM to realize database backup and restoration Introduction: In the development process, database backup and restoration is a very important task. This article will introduce how to use the ThinkORM framework to implement database backup and restoration, and provide corresponding code examples. 1. Background introduction During the development process, we usually use databases to store and manage data. The principle of database backup and restore is to perform regular backups of the database so that the data can be quickly restored in the event of database problems or data loss. With the help of

Backing up your database in Golang is crucial to protecting your data. You can use the database/sql package in the standard library, or a third-party package such as github.com/go-sql-driver/mysql. Specific steps include: Connect to the database. Create a file to store the backup data. Use the Dump function or Exporter to back up the database to a file.
