正文

redhat linux : python installing mysqlclient - mysql_config o

(2024-04-25 17:47:02) 下一個
when we install mysql,postgresql pacakage, we need install mysql-devel and libpq-devel , python need binary of the 2 package 
In Red hat , we can run :
 $ sudo dnf install gcc mysql-devel python3-devel ,

if  we  meet the similar  issues when run " pip install psycopg2" ( this is python Postgresql pkg)

error : pg_config can not be found 

we can run :

sudo dnf install libpq-devel

when the above step is finished , and good ,

then run 

 

$ pip install mysqlclient

then run the sample python , to test connection of Mysql:

############################

#! /usr/bin/env python
#print ("test")
import MySQLdb

# Open database connection
db = MySQLdb.connect("localhost","root","mySql_root_passwd")

# prepare a cursor object using cursor() method
cursor = db.cursor()

# execute SQL query using execute() method.
cursor.execute("SELECT VERSION()")

# Fetch a single row using fetchone() method.
data = cursor.fetchone()
if data:
   print('Version available: ', data)
else:
   print('Version not retrieved.')

# disconnect from server
db.close()

############################

[ 打印 ]
閱讀 ()評論 (0)
評論
目前還沒有任何評論
登錄後才可評論.