Tuesday September 09, 2003
My tips o' the day I found an easy way to update a MySQL database with new columns this morning. The traditional way is to create an ALTER_TABLE script and run it. However, I had added more than 30 columns, and creating this script sounded like a pain in the ass. Keep in mind that I use Hibernate to create my database from scratch - tables, and all. If you're familiar with appfuse, you might be able to use this stuff.
- Dump the existing (production) database using "mysqldump -c database > database.sql". Edit this file, replacing CREATE TABLE with CREATE TABLE IF NOT EXISTS. The "-c" option includes column names in the insert statement.
- Create an empty database (appfuse: ant db-init) and export (mysqldump database > create-tables.sql) it.
- Drop all the tables in the production database (backup first!), mysql < create-tables.sql followed by mysql < database.sql.
Of course, other suggestions are welcome - I'd love to see a mysql diff tool that generates the ALTER script for me!
My other tip is how to start/stop Windows services from the command line - don't know why I haven't used this sooner.
net start "$serviceName"
Where $serviceName is something like "Apache Tomcat 4.1" - use "net start" to see all currently started services.
Posted in General
at Sep 09 2003, 02:07:31 PM MDT
2 Comments
Search This Site
Recent Entries
- Wine Tasting in Napa Valley
- How to build a Shot-Ski
- Bus Project Update
- Farewell to the 2011-2012 Ski Season
- Cruising around the Western Caribbean
- Spring Break!
- A Spectacular Trip to Stockholm and Madrid
- Comparing Web Frameworks and HTML5 with Play Scala at Jfokus 2012
- Play Framework 2.0 with Peter Hilton at Jfokus
- Secure JSON Services with Play Scala and SecureSocial
Posted by Steven Citron-Pousty on September 09, 2003 at 05:24 PM MDT #
If you'd like to post your script here though - feel free. If you wrap it in a <pre> tag, it'll probably look better.
Posted by Matt Raible on September 09, 2003 at 10:32 PM MDT #