How to Baskup and Restore a MySQL database
If you're storing anything in MySQL databases that you do not want to lose, it is very important to make regular backups of your data to protect it from loss. This tutorial will show you two easy ways to backup and restore the data in your MySQL database. You can also use this process to move your data to a new web server.
- Back up From the Command Line (using mysqldump)
- Back up your MySQL Database with Compress
- Restoring your MySQL Database
- Backing Up and Restoring using PHPMyAdmin
Back up From the Command Line (using mysqldump)
If you have shell or telnet access to your web server, you can backup your MySQL data by using the mysqldump command. This command connects to the MySQL server and creates an SQL dump file. The dump file contains the SQL statements necessary to re-create the database. Here is the proper syntax:
- [uname] Your database username
- [pass] The password for your database (note there is no space between -p and the password)
- [dbname] The name of your database
- [backupfile.sql] The filename for your database backup
- [--opt] The mysqldump option
For example, to backup a database named 'Tutorials' with the username 'root' and with no password to a file tut_backup.sql, you should accomplish this command:
This command will backup the 'Tutorials' database into a file called tut_backup.sql which will contain all the SQL statements needed to re-create the database.
With mysqldump command you can specify certain tables of your database you want to backup. For example, to back up only php_tutorials and asp_tutorials tables from the 'Tutorials' database accomplish the command below. Each table name has to be separated by space.
Sometimes it is necessary to back up more that one database at once. In this case you can use the --database option followed by the list of databases you would like to backup. Each database name has to be separated by space.
If you want to back up all the databases in the server at one time you should use the --all-databases option. It tells MySQL to dump all the databases it has in storage.
The mysqldump command has also some other useful options:
--add-drop-table: Tells MySQL to add a DROP TABLE statement before each CREATE TABLE in the dump.
--no-data: Dumps only the database structure, not the contents.
--add-locks: Adds the LOCK TABLES and UNLOCK TABLES statements you can see in the dump file.
The mysqldump command has advantages and disadvantages. The advantages of using mysqldump are that it is simple to use and it takes care of table locking issues for you. The disadvantage is that the command locks tables. If the size of your tables is very big mysqldump can lock out users for a long period of time.
Back up your MySQL Database with Compress
If your mysql database is very big, you might want to compress the output of mysqldump. Just use the mysql backup command below and pipe the output to gzip, then you will get the output as gzip file.
If you want to extract the .gz file, use the command below:
Restoring your MySQL Database
Above we backup the Tutorials database into tut_backup.sql file. To re-create the Tutorials database you should follow two steps:
- Create an appropriately named database on the target machine
- Load the file using the mysql command:
Have a look how you can restore your tut_backup.sql file to the Tutorials database.
To restore compressed backup files you can do the following:
If you need to restore a database that already exists, you'll need to use mysqlimport command. The syntax for mysqlimport is as follows:
Backing Up and Restoring using PHPMyAdmin
It is assumed that you have phpMyAdmin installed since a lot of web service providers use it. To backup your MySQL database using PHPMyAdmin just follow a couple of steps:
- Open phpMyAdmin.
- Select your database by clicking the database name in the list on the left of the screen.
- Click the Export link. This should bring up a new screen that says View dump of database (or something similar).
- In the Export area, click the Select All link to choose all of the tables in your database.
- In the SQL options area, click the right options.
- Click on the Save as file option and the corresponding compression option and then click the 'Go' button. A dialog box should appear prompting you to save the file locally.
Restoring your database is easy as well as backing it up. Make the following:
- Open phpMyAdmin.
- Create an appropriately named database and select it by clicking the database name in the list on the left of the screen. If you would like to rewrite the backup over an existing database then click on the database name, select all the check boxes next to the table names and select Drop to delete all existing tables in the database.
- Click the SQL link. This should bring up a new screen where you can either type in SQL commands, or upload your SQL file.
- Use the browse button to find the database file.
- Click Go button. This will upload the backup, execute the SQL commands and re-create your database.
MySQL Backup software
If you are administrating multiple MySQL servers, you can consider using a commercial solution for MySQL Backup. One solution could be Backup Bird. It is a full cloud server backup service, that monitor the progress of each backup and backup your files as well as your databases.
How to Baskup and Restore a MySQL database的更多相关文章
- Migrate MySQL database using dump and restore
kaorimatz/mysqldump-loader: Load a MySQL dump file using LOAD DATA INFILEhttps://github.com/kaorimat ...
- Backup and Restore MySQL Database using mysqlhotcopy
mysqlhotcopy is a perl script that comes with MySQL installation. This locks the table, flush the ta ...
- Writing to a MySQL database from SSIS
Writing to a MySQL database from SSIS 出处 : http://blogs.msdn.com/b/mattm/archive/2009/01/07/writin ...
- MySQL Database on Azure新功能
本月中国版的MySQL Database on Azure发布了两项新功能: 1.主从复制——只读实例 在这之前Azure上的MySQL数据库也是支持主从复制的,但是只能作为on-premises部署 ...
- CentOS 7 安装 MySQL Database
CentOS 7 安装 MySQL Database 1. 现在安装包,MySQL的安装包被分成了社区版和企业版,而本文将记录社区版本MySQL安装过程,下载MySQL版本如下: mysql-5.7. ...
- mysql-databaseython 3.4.0 with MySQL database
Phttp://shttp://stackoverflow.com/questions/23376103/python-3-4-0-with-mysql-databasetackoverflow.co ...
- MySQL Database on Azure
在国际版的Microsoft Azure上,MySQL服务是与ClearDB合作运营的.由于ClearDB无法在中国地区提供服务,因此微软中国的研发团队开发了专门面向中国市场的MySQL Databa ...
- MySQL Database on Azure 参数设置
在使用MySQL过程中,经常会根据需要对MySQL的参数进行一些设置和调整.作为PaaS版本的MySQL,MySQL Database on Azure在参数设置方面有一些限制,客户不能像使用on-p ...
- MySQL Database on Azure 的用户名
MySQL Database on Azure是中国版Windows Azure上的一个PaaS服务,类似于AWS上的RDS.MySQL Database on Azure的用户名与on-premis ...
随机推荐
- eclipse调试时增加jvm参数
下面的程中我们限制Java 堆的大小为20MB,不可扩展(将堆的最小值-Xms 参数与最大值-Xmx 参数设置为一样即可避免堆自动扩展),通过参数-XX:+HeapDumpOnOutOfMemoryE ...
- [html][javascript] 正则匹配示例
var str="akdlfaklhello 1234klfd1441ksalfd9000kals8998j2345fd;lsa"; var reg = new RegExp(/( ...
- oracle to_date函数和mysql DATE_FORMAT函数用法
一.在Oracle中,当想把字符串为‘2011-09-20 08:30:45’的格式转化为日期格式,我们可以使用oracle提供的to_date函数. sql语句为: SELECT to_date(' ...
- pythonNET day05
孤儿进程 父进程先于子进程退出,此时子进程就会成为孤儿进程. 孤儿进程会被系统指定的进程收养,即系统进程会成为该孤儿进程新的父进程.孤儿进程退出时该父进程会处理退出状态 僵尸进程 子进程先于父进程退出 ...
- Mongodb第一步资料
学习的时候收集了部分好文章,这个文章主要收集的是下载,安装的基本资料 官方http://docs.mongodb.org/manual/tutorial/install-mongodb-on-wind ...
- HTML常用技术
1. 使用a标签实现文件的上传下载 完整代码: <a class="btn btn-success btn-sm" href="http://sf.jb51.net ...
- uva-10879-因数分解
把一个数分解成n*m的形式,一定存在 解题思路: 一个大于1的正整数最小因数一定是素数 ac时间80ms,感觉慢了,可惜看不到0ms的大神代码 #include <iostream> #i ...
- 想取得刚才nextval()的值时,放心大胆的用currval()吧,currval()的返回值并不会因为nextval()的并发访问而混乱
以前写sql的时候总是担心current()得到的值并不会绝对等于我上一次nextval()取得的值;因为可能其他线程并发访问nextval(). 先说结论吧:当你拿到一个数据库连接,先nextval ...
- Ubuntu12.04编译vlc-android详细流程
作者:wainiwann 出处:http://www.cnblogs.com/wainiwann/ 本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则 ...
- The web application [/zzti] registered the JDBC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver
先说下题目:因为是在我进行处理项目升级时同时遇到了上面的问题,一般都会遇到,所以就一并说了 不罗嗦了,正题: 在本地服务器中提供tomcat6,然后在myeclipse中配置severs tomcat ...