MySQL backup - How to backup a MySQL database
2015-06-18 19:48
676 查看
MySQL backup FAQ: How do I backup a MySQL database?
I can't speak about backing up MySQL databases that are modified twenty-four hours a day seven days a week, but on all the MySQL databases I currently work with, there are always times when I can guarantee that there won't be any SQL INSERTs, DELETEs, or UPDATEs occurring, so I find it's really easy to perform a MySQL backup using the mysqldump utility program. Here's how it works.
Create a MySQL backup with mysqldump
I was just working on a Drupal database, and decided that I wanted to make a backup of Drupal's MySQL database before I did something that might screw up the database (converting a WordPressdatabase to a Drupal database). So, I made a backup of my current MySQL Drupal database using the followingmysqldumpcommand:
mysqldump --opt --user=root --password drupaldb > drupaldb-20090505.sql
Note that in this command,
drupaldbis the name of my database, not the password. The
--passwordargument just tells MySQL to prompt me for the password, because I don't want to type it right here on the command line. So, immediately after I enter that command, MySQL prompts me for the
rootuser's password, like this:
Enter password: _
Once I enter that password, my
drupaldbdatabase is dumped to a file in the current directory named
drupaldb-20090505.sql.
MySQL backup - A slightly different syntax
Note that you can also enter yourmysqldumpcommand as shown next, which is equivalent to the previous command:
mysqldump --opt -u root -p drupaldb > drupaldb-20090505.sql
In both of these examples, the
20090505portion of the filename just indicates today's date, May 5, 2009. (Happy Cinco de Mayo. :)
MySQL backup - The general form of mysqldump
That was one specific example of themysqldumpcommand. The general form of the backup command is shown here:
mysqldump --opt -u username -p database-name > backup-file-name
where:
usernamecan be
root, if you know the
rootpassword, or it can be the name of the MySQL user that owns your database.
database-nameis the name of your database, which in my case was
drupaldb.
backup-file-nameis the name of the backup file you want to create. This will be a plain text file that the
mysqldumpcommand creates for you.
MySQL database backup shell script
I just created a new MySQL database backup (dump) shell script to automate MySQL backups. In addition to creating this shell script, I've added new MySQL command line options not shown in this example. If you need to use additional mysqldump command line options, see that article for more information.相关文章推荐
- ubuntu14源码安装mysql5.7
- MySQLdb autocommit
- mysql int(3)与int(11)的区别
- JDBC连接MySQL字符集错误解决办法
- [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL s
- mysql主从同步配置步骤
- mysql排序后取第一条数据
- MySQL5.6之Index Condition Pushdown(ICP,索引条件下推)
- MySQLdb callproc 方法
- mysql group by中没有的字段 select中可以有
- 查看mysql数据库大小、表大小和最后修改时间
- ERROR 2003 (HY000): Can't connect to MySQL server on "host" (111)
- Mysql导出表结构及表数据 mysqldump用法
- MySQL用户及权限设置
- mysql 基本增删改查
- mysql主从复制(windows下)
- mysql重连的问题
- MySql怎样追踪用户操作(增删改)记录
- Pthon MySQLdb 的安装
- MYSQL SHOW PROCESSLIST 各状态含义