mysql_config not found when installing mysqldb python interface

前端 未结 30 1890
暗喜
暗喜 2020-11-22 06:56

I am trying to get a Python script to run on the linux server I\'m connected to via ssh. The script uses mysqldb. I have all the other components I need, but when I try to i

30条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 07:39

    I think the most convenient way to solve this problem in 2020 is using another python package. We don't need install any other binary software.

    Try this

    pip install mysql-connector-python

    and then

    import mysql.connector
    
    mydb = mysql.connector.connect(
              host="",
              user="",
              passwd="",
              database=""
              )      
    cursor = mydb.cursor( buffered=True)
    cursor.execute('show tables;')
    cursor.execute('insert into test values (null, "a",10)')
    mydb.commit()
    mydb.disconnect()

提交回复
热议问题