Creating Test and Production Sites with Only One IIS Server - Step 2: It Looks Like the Database, and Smells Like the Database
(Page 3 of 5 )
Once again, there are two parts to this step. So now you're thinking “hey, if there are two parts to this step, and same with the last, and who knows how many parts for the next steps, it's really not a 4-step process!” Yes, you're right, I apologize. I wasn't trying to trick you! But hey, if it was really only 4 steps, there would probably be no need for a tutorial, right?
Now that we've gotten that little discrepancy settled, let's discuss the first part: copying the database.
As I mentioned, I was using MySQL, and MySQL has a wonderful little tool called mysqldump. With this tool, you can easily create a 'dump' of the database, either of the structure only, or even the structure and all content with it. The 'dump' file is a text files filled with SQL commands that would recreate the structure [and optionally the content]. This is normally a .sql file. Once we have the .sql file, we can feed that back into MySQL, into a second – or 'test' – database.
So here's how I did this. First, I created a second, empty database called dbTest. I then made sure the SQLuser (used in the application) user had the same permissions on this database. Then I opened up my command prompt, and typed the following:
cd C:mysqlbin (your install dir here)
mysqldump --quick --user=root --password=******* dbProd > c:bkp.sql
This creates dump file. Now we feed it back into the test database:
mysql --user=root --pass=******* dbTest < c:bkp.sql
There you go. Depending on the size of the database, this shouldn't take too long. One quick caveat. If you are using InnoDB tables, and have foreign keys set throughout the tables, you will need one intermediate step before feeding the .sql file back in. You need to open the .sql file (in notepad or something similar) and enter the following on the first line:
SET FOREIGN_KEY_CHECKS=0;
This will prevent the error that MySQL would produce when it's trying to check the foreign key constraints against records that haven't yet been created.
Now that was the first part. If you've designed your application properly, and no doubt you have, the second step will be extremely easy. You just need to change the connection settings in your test code to point to the test database instead. Hopefully you have the connection settings in either a global.asa (ASP v3.0) file, or in the web.config (ASP.Net) file. You can just make the change to point to the dbTest server instead. If you are using DSN, you will need to create a new DSN entry for the test database, and point your test code to that.
Next: Step 3: Configuring IIS >>
More IIS Articles
More By Justin Cook