ImportError: no module named 'MySQLdb'



  • I use pymakr to connect my LoPy with MySQLdb but there is error ( ImportError: no module named 'MySQLdb' ) what am I suppose to do?
    my code is:
    import MySQLdb

    db = MySQLdb.connect(host="localhost", # your host, usually localhost
    user="root", # your username
    passwd="", # your password
    db="solarchargermonitoring") # name of the data base

    you must create a Cursor object. It will let

    you execute all the queries you need

    cur = db.cursor()

    Use all the SQL you like

    cur.execute("SELECT * from regisperangkat")

    print all the first cell of all the rows

    for row in cur.fetchall():
    print(row)

    db.close()



  • @fajriansyah
    I do not know if some "minimal" client exists for micropython. But is it required?
    Better run some listen socket on your server. And then your Lopy will send messages to this socket and it connect to jour database and store there data. It can be e.g. windows service apllication, webserver application e.g. on IIS, Apache + php ....



  • This post is deleted!


  • @livius @jcaron sorry, I mean lopy will connect with my database (local host). Can it?



  • @fajriansyah
    You probably mismatch things
    on Lopy you have micropython not full python because hardware resources are too limited.



  • @fajriansyah you most certainly won’t be running a MySQL server on a LoPy, and I’m not sure there are any scenarios where it would make sense to connect directly to one from a LoPy either. Calling a webservice or sending data over LoRa to a server which would in turn connect to a MySQL database would probably make more sense.

    What exactly are you trying to achieve?



Pycom on Twitter