一、mysql 的管理
字段名
|
数字类型
|
数据宽度
|
是否为空
|
是否主键
|
自动增加
|
默认值
|
id
|
int
|
4
|
否
|
primary key
|
auto_increment
|
|
name
|
char
|
20
|
否
|
|
|
|
sex
|
int
|
4
|
否
|
|
|
0
|
degree
|
double
|
16
|
是
|
|
|
|
Shell> mysqldump [OPTIONS] database [tables]
|
mysqldump --opt database > backup-file.sql
|
mysqldump --opt database | mysql --host=remote-host -C database
|
shell> mysqladmin create target_db_name
shell> mysql target_db_name < backup-file.sql
|
#!/bin/bash
#This is a ShellScript For Auto DB Backup
#Powered by aspbiz
#2004-09
#Setting
#
设置数据库名,数据库登录名,密码,备份路径,日志路径,数据文件位置,以及备份方式
#
默认情况下备份方式是
tar
,还可以是
mysqldump,mysqldotcopy
#
默认情况下,用
root(
空
)
登录
mysql
数据库,备份至
/root/dbxxxxx.tgz
DBName=mysql
DBUser=root
DBPasswd=
BackupPath=/root/
LogFile=/root/db.log
DBPath=/var/lib/mysql/
#BackupMethod=mysqldump
#BackupMethod=mysqlhotcopy
#BackupMethod=tar
#Setting End
NewFile="$BackupPath"db$(date +%y%m%d).tgz
DumpFile="$BackupPath"db$(date +%y%m%d)
OldFile="$BackupPath"db$(date +%y%m%d --date='5 days ago').tgz
echo "-------------------------------------------" >> $LogFile
echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile
echo "--------------------------" >> $LogFile
#Delete Old File
if [ -f $OldFile ]
then
rm -f $OldFile >> $LogFile 2>&1
echo "[$OldFile]Delete Old File Success!" >> $LogFile
else
echo "[$OldFile]No Old Backup File!" >> $LogFile
fi
if [ -f $NewFile ]
then
echo "[$NewFile]The Backup File is exists,Can't Backup!" >> $LogFile
else
case $BackupMethod in
mysqldump)
if [ -z $DBPasswd ]
then
mysqldump -u $DBUser --opt $DBName > $DumpFile
else
mysqldump -u $DBUser -p$DBPasswd --opt $DBName > $DumpFile
fi
tar czvf $NewFile $DumpFile >> $LogFile 2>&1
echo "[$NewFile]Backup Success!" >> $LogFile
rm -rf $DumpFile
;;
mysqlhotcopy)
rm -rf $DumpFile
mkdir $DumpFile
if [ -z $DBPasswd ]
then
mysqlhotcopy -u $DBUser $DBName $DumpFile >> $LogFile 2>&1
else
mysqlhotcopy -u $DBUser -p $DBPasswd $DBName $DumpFile >>$LogFile 2>&1
fi
tar czvf $NewFile $DumpFile >> $LogFile 2>&1
echo "[$NewFile]Backup Success!" >> $LogFile
rm -rf $DumpFile
;;
*)
/etc/init.d/mysqld stop >/dev/null 2>&1
tar czvf $NewFile $DBPath$DBName >> $LogFile 2>&1
/etc/init.d/mysqld start >/dev/null 2>&1
echo "[$NewFile]Backup Success!" >> $LogFile
;;
esac
fi
echo "-------------------------------------------" >> $LogFile
|
#back for mysql database
10 0 * * * /root/dbbackup
|
1)、把远程mysql服务器上的选定表的指定数据导入到本地的文本文件中: [hello@localhost hello]$ mysqldump -hhostname -uusername -p -w "last>'2007-01-01'" dbname tablename > ./filename Enter password: 2)、把远程mysql服务器上的选定数据库的全部数据导入到本地的文本文件中: [hello@localhost hello]$ mysqldump -hhostname -uusername -p dbname > ./filename Enter password: 3)、把远程mysql服务器上的选定表的指定数据导入到服务器的文本文件中(所以在本地不能操作如下): mysql> use dbname; mysql> select fieldname into outfile '/home/hello/a.txt' from tablename where last>"2007-1-1"; ERROR 1045: Access denied for user: 'hello@%' (Using password: YES) mysql> 4)、把远程mysql服务器上的选定表的指定数据导入到本地的文本文件中: [hello@localhost hello]$ mysql -e "select fieldname from tablename where last>'2007-1-1'" -hhostname -uusername -p dbname > ./filename Enter password: |