Search code examples
pythonmysqlmysql-connector-pythonflask-mysql

Flask-mysqldb vs Mysql-connector-python


I'm new in the world of Python and WebApps, nowadays I'm trying to improve my level.

I would like to build a WebApp with Flask but I'm confuse in which BBDD connector use and what's the difference between them.

What's the diference between Flask_mysqldb and Mysql-connector-python and which one should I use?

Thanks a lot!


Solution

  • both Flask_mysqldb and Mysql-connector-python are python libs for mysql, they are written by different person, but they do the same work , makes you access the mysql database more easier.

    You can choose any one to use, then find the usages from official website or other learning website, just search them in google n_n

    All the libs related to database which connect db directly are the same, write some config to set your environment, and some method like connect() to connect with database, then get 'cursor', use execute() or other method to execute your sql statement.

    I used pymysql, you can get my code from github https://github.com/frankxii/myblog/blob/master/myblog/models/init.py

    usage:

    import pymysql
    
    conf = {
        "host": "127.0.0.1",
        "port": 3306,
        "user": "root",
        "passwd": "mysql1234",
        "charset": "utf8mb4",
        "cursorclass": pymysql.cursors.DictCursor,
        "database": "test"
    }
    conn = pymysql.connect(**conf)
    cursor = conn.cursor()
    cursor.execute("SELECT * FROM test")