Recently I needed to rename a MySQL database I was working with to make way for another with the same name. When I looked around for how to do this it seemed that the only option was to create the new database and then copy each table to it, via INSERT...SELECTs or a dump and import. It was quite a large database and this would have been very time consuming.
Tips and tricks for LAMP (Linux Apache MySQL PHP) developers.
When I cant find a suitable solution to a problem and have to work it out for myself I'll post the result here so hopefully others will find it useful. (All code is offered in good faith. It may not be the best solution, just a solution).
Saturday, 12 November 2011
Rename a MySQL database
After discussing it with a colleague we came up with another way to do it by using bash to iterate over each table in the schema and then use the RENAME TABLE command:
for TABLE in `mysql -u[USERNAME] -p[PASSWORD] [OLD DB] -e "SHOW TABLES" -B -N -s`; do mysql -u[USERNAME] -p[PASSWORD] [OLD DB] -e "RENAME TABLE [OLD DB].$TABLE TO [NEW DB].$TABLE"; done;
This worked a treat (I've been using my new database reliably for a while now) and was fast too!
Sunday, 26 September 2010
Symlinks in Windows
Not strictly a LAMP tip this as it's for Windows but I found it useful recently.
I'm using the rather awesome XAMPP to do some development for one of my personal sites on my Windows machine and I wanted to symlink my codebase into XAMPP's equivalent of a 'public_html' folder (they call it 'htdocs'). I tried simply creating a shortcut but this doesn't work as a shortcut isn't a direct pointer but is a file in itself so Apache just tries to read that file.
After much Googling I discovered that, since Vista, Microsoft have introduced a symlinking function, MKLINK:
MKLINK /D C:\path\to\link C:\path\to\target
The /D specifies a link to a directory as the default is to a file.
This worked a treat on my Windows 7 machine! Who knew Vista introduced something useful?! ;)
Monday, 19 April 2010
Colour Schemes
This is more for designers than developers but some of us have to do both :)
When coming up with a colour scheme for a site or UI it's a good idea to use colours that compliment each other. This isn't just a design thing, it's partly mathematical and there are some sites out there that can calculate compatible colours for you.
This is a good example: http://colorschemedesigner.com/
Another thing that can be useful is the ability to blend two colours together. http://meyerweb.com/eric/tools/color-blend/ allows you to input two hex colour values and it will give you the resulting hex colour value.
Subscribe to:
Posts (Atom)