title: Python MySQL escape special characters
body: <p>I am using python to insert a string into MySQL with special characters.</p>
  
  <p>The string to insert looks like so:</p>
  
  <pre><code>macaddress_eth0;00:1E:68:C6:09:A0;macaddress_eth1;00:1E:68:C6:09:A1
  </code></pre>
  
  <p>Here is the SQL:</p>
  
  <pre><code>UPGRADE inventory_server 
  set server_mac = macaddress\_eth0\;00\:1E\:68\:C6\:09\:A0\;macaddress\_eth1\;00\:1E\:68\:C6\:09\:A1' 
  where server_name = 'myhost.fqdn.com
  </code></pre>
  
  <p>When I execute the update, I get this error:</p>
  
  <pre><code>ERROR 1064 (42000): 
  You have an error in your SQL syntax; check the manual that corresponds to your 
  MySQL server version for the right syntax to use near 'UPGRADE inventory_server 
  set server_mac = 'macaddress\_eth0\;00\:1E\:68\:C6\:09\' at line 1
  </code></pre>
  
  <p>The python code:</p>
  
  <pre><code>sql = 'UPGRADE inventory_server set server_mac = \'%s\' where server_name = \'%s\'' % (str(mydb.escape_string(macs)),host)
  print sql
  
  try:
      con = mydb.connect(DBHOST,DBUSER,DBPASS,DB);
      with con:
         cur = con.cursor(mydb.cursors.DictCursor)
         cur.execute(sql)
     con.commit()
  except:
  return False
  </code></pre>
  
  <p>How can I insert this text raw?</p>