SoFunction
Updated on 2025-03-01

Steps to connect to MySQL in IronPython

I thought it was easy to use MySQL in IronPython. Even if there was trouble, I could change the path and load the MySQL module under Python. It turns out that this is my wishful thinking. To connect to MySQL database in IronPython, you must call the dynamic library - this dll is easy to find online, but how to use this library, the information on the Internet is rare and difficult to find. I finally found a few articles, but I was vague and didn't know what to say.

After a lot of trouble, I finally figured out the usage.

1. Import module

import clr
("")
from  import * 

2. Connect to the database

conStr = 'server=%s; user id=%s; password=%s; database=%s; pooling=false; charset=gbk' % (host, user, passwd, db) 
db = MySqlConnection(conStr) 
() 
 

3. Perform insert (update, delete, etc.)

sqlStr = "INSERT INTO ..." 
cmd = MySqlCommand(sqlStr, db) 
rows = () 

4. Execute the query statement

cmd =  () 
 = "SELECT ..." 
r =  () 
tagList = [] 
while  (): 
  (r['rfidLabel']) 
 () 
return tag in tagList 

5. Close the connection

 ()

How about it? Does the code style feel a bit weird?

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.