Diferencia entre revisiones de «MySQL»

De gacq wiki
Saltar a: navegación, buscar
(Performance)
(Scripts)
Línea 27: Línea 27:
  
 
=Scripts=
 
=Scripts=
 +
==Hot backup - One database==
 +
#!/bin/sh
 +
# by gacq
 +
#
 +
PASSWORD=$1
 +
DATABASE=$2
 +
OUTPUTDIR="/srv/backup/mysql"
 +
 +
# Delete backups older than the number of days specified in DAYS
 +
DAYS=8
 +
 +
date=`date +%F_%T | tr \: _`
 +
mysqldump --password=$PASSWORD $DATABASE | gzip > $OUTPUTDIR/$DATABASE-${date}.sql.gz
 +
 
 +
# Delete older backups
 +
find $OUTPUTDIR -type f -name "all-databases.*.sql" -ctime $DAYS -exec rm -f {} \;
 +
 
==Hot backup - All databases==
 
==Hot backup - All databases==
 
  #!/bin/sh
 
  #!/bin/sh
Línea 44: Línea 61:
 
  find $OUTPUTDIR -type f -name "all-databases.*.sql" -ctime $DAYS -exec rm -f {} \;
 
  find $OUTPUTDIR -type f -name "all-databases.*.sql" -ctime $DAYS -exec rm -f {} \;
  
==Hot backup - One database==
+
==Hot backup - All databases, each database in a separated file==
 
  #!/bin/sh
 
  #!/bin/sh
 
  # by gacq
 
  # by gacq
 
  #
 
  #
 +
# MySQL root password
 
  PASSWORD=$1
 
  PASSWORD=$1
  DATABASE=$2
+
  BASEDIR="/srv/backup/mysql"
OUTPUTDIR="/srv/backup/mysql"
 
 
   
 
   
 
  # Delete backups older than the number of days specified in DAYS
 
  # Delete backups older than the number of days specified in DAYS
Línea 56: Línea 73:
 
   
 
   
 
  date=`date +%F_%T | tr \: _`
 
  date=`date +%F_%T | tr \: _`
  mysqldump --password=$PASSWORD $DATABASE | gzip > $OUTPUTDIR/$DATABASE-${date}.sql.gz
+
   
 +
OUTPUTDIR="$BASEDIR/mySQLbackup_$date"
 +
mkdir -p $OUTPUTDIR
 +
 +
databases=`echo "show databases;" | mysql -Bs -uroot -p$PASSWORD`
 +
for db in `echo $databases`
 +
do
 +
  mysqldump --password=$PASSWORD $db | gzip > $OUTPUTDIR/mySQLdump-$db-${date}.sql.gz
 +
done
 
   
 
   
 
  # Delete older backups
 
  # Delete older backups
  find $OUTPUTDIR -type f -name "all-databases.*.sql" -ctime $DAYS -exec rm -f {} \;
+
  find $BASEDIR -type d -name "mySQLbackup*" -ctime $DAYS -exec rm -fr {} \;
 +
 
  
 
==Selected databases==
 
==Selected databases==

Revisión del 17:07 17 abr 2007

Documentation

Tools

Performance

Syntax

Select

CONCAT(first_name, ' ', last_name)

Integration

Authentication using LDAP, kerberos, etc is not ready yet

Common task

Change password

set password = password("yournewpassword");

Scripts

Hot backup - One database

#!/bin/sh
# by gacq
#
PASSWORD=$1
DATABASE=$2
OUTPUTDIR="/srv/backup/mysql"

# Delete backups older than the number of days specified in DAYS
DAYS=8

date=`date +%F_%T | tr \: _`
mysqldump --password=$PASSWORD $DATABASE | gzip > $OUTPUTDIR/$DATABASE-${date}.sql.gz
 
# Delete older backups
find $OUTPUTDIR -type f -name "all-databases.*.sql" -ctime $DAYS -exec rm -f {} \;

Hot backup - All databases

#!/bin/sh
# by gacq
#
# MySQL root password
PASSWORD=$1
OUTPUTDIR="/srv/backup/mysql"

# Delete backups older than the number of days specified in DAYS
DAYS=8

date=`date +%F_%T | tr \: _`
mysqldump --all-databases --password=$PASSWORD | gzip > $OUTPUTDIR/all-databases-${date}.sql.gz

# Delete older backups
find $OUTPUTDIR -type f -name "all-databases.*.sql" -ctime $DAYS -exec rm -f {} \;

Hot backup - All databases, each database in a separated file

#!/bin/sh
# by gacq
#
# MySQL root password
PASSWORD=$1
BASEDIR="/srv/backup/mysql"

# Delete backups older than the number of days specified in DAYS
DAYS=8

date=`date +%F_%T | tr \: _`

OUTPUTDIR="$BASEDIR/mySQLbackup_$date"
mkdir -p $OUTPUTDIR

databases=`echo "show databases;" | mysql -Bs -uroot -p$PASSWORD`
for db in `echo $databases`
do
  mysqldump --password=$PASSWORD $db | gzip > $OUTPUTDIR/mySQLdump-$db-${date}.sql.gz
done

# Delete older backups
find $BASEDIR -type d -name "mySQLbackup*" -ctime $DAYS -exec rm -fr {} \;


Selected databases

databases="db1 db2 db3"
for db in `echo $databases`
do
  mysqldump -uroot -p$passwd $db | gzip > $dir/mySQL/mySQLdump-$db.dump.gz
done