The Blog

Author: admin

Backup and Restore compressed MySQL databases using gz or bz2

Posted on

Backup

mysqldump --routines -u root -p --databases db1 db2 db3 | gzip > /var/www/backups/mysql/databases.sql.gz # multiple db using gzip
mysqldump --routines -u root -p --databases db1 db2 db3 | bzip2 > /var/www/backups/mysql/databases.sql.bz2 # multiple db using bz2

mysqldump --routines -u root -p db1 | gzip > /var/www/backups/mysql/db1.sql.bz2 # single db using gzip
mysqldump --routines -u root -p db1 | bzip2 > /var/www/backups/mysql/db1.sql.bz2 # single db using bz2

Restore

bunzip2 < db1.sql.bz2 | mysql -u root -p db1
zcat db1.sql.gz | mysql -u root -p db1

Same goes for multiple DBs just add one or more DB to restore at the end of the command, or leave blank to restore all.

Posted in Uncategorized Leave a comment

ORDER BY with NULL at the bottom

Posted on

MySQL has an undocumented syntax to sort nulls last. Place a minus sign (-) before the column name and switch the ASC to DESC:

SELECT * FROM tablename WHERE visible=1 ORDER BY -position DESC, id DESC

It is essentially the inverse of position DESC placing the NULL values last but otherwise the same as position ASC.

Posted in MySQL Leave a comment

Loading assets from a different server

Posted on

In a production environment you’ll eventually want to load assets (images, CSS and JS) from a different server. Perhaps you’re running your own asset server or you’re even using a CDN. This will require the files to be linked with an absolute URL. But in your development environment you don’t want this – you want assets to be loaded directly from the same server.
Read More

Posted in Symfony3 Leave a comment
« Previous PageNext Page »