title: Switching from SQLite to MySQL with Flask SQLAlchemy
body: <p>I have a site that I've built with Flask SQLAlchemy and SQLite, and need to switch to MySQL. I have migrated the database itself and have it running under MySQL, but </p>
  
  <ol>
  <li>Can't figure out how to connect to the MySQL database (that is, what the <code>SQLALCHEMY_DATABASE_URI</code> should be) and</li>
  <li>Am unclear if any of my existing SQLAlchemy SQLite code will work with MySQL.</li>
  </ol>
  
  <p>I suspect that (1) is fairly simple and just a matter of being shown how to map, for example, the contents of the connection dialog I use in my MySQL database tool to an appropriately formatted URL. But I'm worried about (2), I had assumed that SQLAlchemy provided an abstraction layer so that <a href="https://pythonhosted.org/Flask-SQLAlchemy/quickstart.html#a-minimal-application">simple SQLAlchemy code such as</a> </p>
  
  <pre><code>from flask import Flask
  from flask.ext.sqlalchemy import SQLAlchemy
  
  app = Flask(__name__)
  app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
  db = SQLAlchemy(app)
  
  
  class User(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      username = db.Column(db.String(80), unique=True)
      email = db.Column(db.String(120), unique=True)
  
      def __init__(self, username, email):
          self.username = username
          self.email = email
  
      def __repr__(self):
          return '&lt;User %r&gt;' % self.username
  
  admin = User('admin', 'admin@example.com')
  
  db.session.add(admin)
  
  User.query.all()
  
  User.query.filter_by(username='admin').first()
  </code></pre>
  
  <p>wold work without any modifications other than an appropriate change to the database URI; but the <a href="http://pylonsdevelopment.blogspot.com/2010/07/connecting-to-mysql-database-using.html">examples I've found</a> for using SQLAlchemy with MySQL seem to use a completely different API.</p>
  
  <p>Can I (2) migrate my Flask SQLAlchemy code to work with a MySQL database by simply changing the database URI and if so (1) what should that URI be?</p>