Skip to content

Instantly share code, notes, and snippets.

@ferstar
Last active January 13, 2016 13:22
Show Gist options
  • Save ferstar/387b20c9468979ddd5f6 to your computer and use it in GitHub Desktop.
Save ferstar/387b20c9468979ddd5f6 to your computer and use it in GitHub Desktop.
scripts about mysql
#!/bin/sh
# Name:bakmysql.sh
# This is a ShellScript For Auto DB Backup and Delete old Backup
#
backupdir=/home/sqlbak
mysql_bin_dir=/usr/bin
time=`date +%Y%m%d`
dbname1=
dbname2=
username=
passwd=
host=
$mysql_bin_dir/mysqldump -u $username -p$passwd -h $host $dbname1 | gzip > $backupdir/bak-$dbname1-$time.sql.gz
$mysql_bin_dir/mysqldump -u $username -p$passwd -h $host $dbname2 | gzip > $backupdir/bak-$dbname2-$time.sql.gz
find $backupdir -name "*.gz" -type f -mtime +7 -exec rm {} \; > /dev/null 2>&1
@ferstar
Copy link
Author

ferstar commented Jan 5, 2016

数据库迁移

# 备份远程数据库数据
mysqldump -u username -p -h sql_server_host database_name > database_name.sql
# 新建数据库
create database database_name;
show databases;
# 添加用户/密码
create user 'username' IDENTIFIED BY 'password';
# 设定数据库访问权限
grant all on database_name.* to username IDENTIFIED BY 'password';
flush privileges;
# 还原数据库备份
mysql -uusername -ppassword database_name < database_name.sql
或
gzip < database_name.sql.gz | mysql -u root -p dataname
或:
zcat database_name.sql.gz  | mysql -u root -p dataname

WordPress配置部分"wp-config.php"

/** MySQL主机 */
define('DB_HOST', 'localhost');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment