标签归档:dh

每天自动备份MYSQL数据库(dh空间)

Getting a Backup From the ShellYou can use the mysqldump shell command to make a backup, also. This is more difficult to do the first time than the phpMyAdmin method above, but you can automate it so that the system backs up your database for you. See Automatic Backup for instructions on how to automate this.

  1. Log into your old server with SSH or Telnet
  2. Type the following command:

mysqldump –opt -uusername -ppassword -h yourMySQLHostname dbname > output.sql

  1. Log into your account with FTP and download the newly created output.sql file.

在查找“用SSH备份mysql”时,发现的——“Dreamhost下每天自动备份mysql数据库,并发送到指定邮箱”。
觉得比wordpress的一些备份plugin好,决定启用。

1、用putty登录你的dreamhost;

2、运行

<LI class=hl-firstline>cd ~
mkdir backups
mkdir backups/archives

3、新建一个名为“.sh”的文件,并输入下列代码:

<LI class=hl-firstline>#!/bin/bash
cd /home/username/backups/ #username改为你登录ssh时用的用户名
mkdirmysql
suffix=$(date +%y%m%d)
mysqldump –opt -uUser -pPass -hmysqlA.domain.comdb_nameA > mysql/db_nameA.$suffix.sql#User为数据库用户名,pass为数据库用户密码,mysqlA.domain.com为数据库地址,db_nameA为数据库名,请根据你的情况修改。
tarzcfarchives/mysql_backup.$suffix.tar.gzmysql/*
rm -rmysql/
muttyou@domain.com -a /home/username/backups/archives/mysql_backup.$suffix.tar -s“MySQL Backup“#you@domain.com修改为你准备用于收取备份压缩包的邮箱。
保存后,上传到backups文件夹中。

4、在putty中运行

<LI class=hl-firstline>dos2unix ~/backups/mysql.sh
chmod 755 ~/backups/mysql.sh

5、在Dreamhost的panel,Goodies->Cron Jobs中新建Cron任务,选项设置为
Command to run: /home/User/backups/mysql.sh
#User改为你登录SSH时用的用户名。

时间照下图设置,将在北京时间每天的24:10左右运行备份MySQL程序,并发送备份压缩包到你指定的邮箱。

open_img('attachments/200802/3734208507.jpg')

dreamhost(DH)空间MYSQL数据库备份方法

如何利用SSH(Shell)来备份和恢复MySQL数据库的方法
例如:
数据库参数为::
MySQL地址:.dh.net
MySQL名称:mysql_dbname
MySQL用户:mysql_dbuser
MySQL密码:mysql_dbpass

我要把数据库备份为bak.sql

步骤:
同样,使用windows系统自己带的telnet或者去下载一个putty来,登陆以后,一路cd到自己觉得合适的目录下(确认当前目录可写).
输入下面的命令:
mysqldump -h mysql.dh.net -p mysql_dbname -u mysql_dbuser >bak.sql
然后回车,提示你输入数据库登陆密码,输入完密码后回车,OK! 就把数据库备份到当前目录下了

如何恢复bak.sql数据库:::
输入下面命令后回车
mysql -h mysql.dh.net -p mysql_dbname -u mysql_dbuser
提示你输入密码,输入密码后然后回车
会出现MySQL操作提示符号
然后输入下面的命令
source bak.sql
请先确认bak.sql这个文件再当前目录下
回车.OK,恢复ing…..