Category: Uncategorized

MySQL to Azure SQL Database Migration

I’ve been experimenting lately with Azure and wanted to kick the tires of SQL Database with a real dataset that I have. It turns out that this is pretty straightforward, but I had to collect information from a number of sources. Here are my notes – hope they are helpful:

  1. You’ll need a Windows machine to run SQL Server Management Studio (SSMS) and an Azure account with your target SQL Database provisioned.  There is a great walk through on how to do that written up in the Azure documentation.  Follow the steps there to get SSMS connected to your Azure db instance.   
  2. Install the MySQL ODBC Connector if you haven’t already.
  3. Install the SQL Server Migration Assistant for MySQL (SSMA).   Note: You actually need to install both it and an extension pack that are bundled in the same zip file you download.
  4. Run SQL Server Migration Assistant for MySQL.   It’ll prompt you for a license, which requires jumping back to the Microsoft site, and moving this license file to a path that it gives you.
  5. Click “Connect to MySQL” in the top left corner.  Point SSMA to your MySQL instance and connect.   SSMA will introspect the instance and give you a list of the databases you can connect to.   Check off the database you’d like to migrate.
  6. Click “Connect to SQL Azure”.   You’ll need your SQL Database server’s instance name from the Azure Management Portal, which should look something like this:  kcpnnc4bcy.database.windows.net and your user name and password for the db instance that you created in step 1.   Check off the database you created.
  7. Ok, we’ve connected the two databases.  Expand the node for your MySQL database and check off the items that you want migrated.
  8. SSMA can do a dry run of the schema conversion and produce a report.   Do this by right clicking the “Tables” node on your MySQL connection and selecting “Create Report.”   I had 70 odd warnings to work down through – all were slight collation and schema differences that I could safely ignore – but check them all anyway.
  9. It takes three steps to get your data migrated.   Right click your MySQL “Tables” node again and click “Convert Schema.”   This will create the schema on your Azure SQL Database.  Check that over and make sure it looks good to go.
  10. Right click your new Azure SQL Database and select “Synchronize with Database”.   This force you to enter credentials again for both databases and then will synchronize schemas and indexes.
  11. Finally, right click the “Tables” node for your MySQL database and select “Migrate Database”.   Enter your credentials again and SSMA will jump into migrating the data.

Walkthrough: Ruby on Rails on Windows Azure

I setup Ruby on Rails on a new shiny Windows Azure VM instance today and I thought I’d share this walkthrough on how to get yourself up and running.

First off, you’ll need a virtual machine running one of the Linux distributions. To do that, go to your Windows Azure management console and click “+ New” -> “Virtual Machine” -> “From Gallery” -> “Ubuntu Server 12.04”.

Move to page #2 and name the machine (I called mine “frontend”) and choose a username and password. On page #3, choose a DNS name for the url that you’ll use for this app (you’ll need it down below, so make a note of it). On page #4, just accept the defaults.

After a minute or so of provisioning work, your VM should come up and go green.

Using your favorite SSH program, attach to a shell on the machine by using the login credentials you created previously and the DNS name you assigned above.

ssh <username>@<dns-address>.cloudapp.net

Entering your password should drop you to the Linux command line in your VM.

Ok, we’re ready to get started! The first thing we need to install is RVM (Ruby Version Manager). You can do that like this:

curl -L get.rvm.io | bash -s stable

This should download and setup rvm. You only then need to source rvm’s script to get all of the paths loaded into the environment.  Look in the output of the last command for the appropriate command for you (mine given as reference below).

source /home/testapp/.rvm/scripts/rvm

Next, we need to find out what dependencies we have for installing ruby. rvm has a command for that.

rvm requirements

Copy the requirements and prepend them with a sudo to install them (below are my dependencies as of this writing for reference):

sudo /usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion

Now that we have the ruby version manager and dependencies, installing Ruby is easy. I’ll use 1.9.3 here, which is the current stable version:

rvm install 1.9.3

This will take some time to complete. Afterwards, we’ll want to make this the default version as well:

rvm use 1.9.3 --default

Next, we’ll install RubyGems, the package management app for Ruby:

sudo apt-get install rubygems

and then install the Ruby on Rails gem using RubyGems:

sudo gem install rails

Finally, we need a javascript runtime for Rails. I’ll install that here by installing node.js to keep it simple.

sudo apt-get install python-software-properties
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm

All of the installation work should now be completed. Let’s create a test application to try it all out:

cd ~
rails new testapp
cd testapp
rails server

This fires up the Rails WEBrick development server with the default port binding (3000), which you can open up to the world from the Azure virtual machine dashboard for this machine. Click “endpoints” at the top, select “Add Endpoint” at the bottom, and add a TCP endpoint with the name “web” and public/private ports of 3000, and, voila, that should be it. You should have a running Ruby on Rails application on Azure — typing http://<name of your app>.cloudapp.net:3000/ in your browser should bring up the default Rails home page.

Using the development WEBrick server is obviously not production ready, but given that this is real honest to goodness Ubuntu machine, there are existing walkthroughs for getting passenger and NGINX setup that can help you through that.