Home > database >  Python3.6 mysql, via pymysql connection error, please answer
Python3.6 mysql, via pymysql connection error, please answer

Time:09-27

Source program following
The import pymysql
The connect=pymysql. Connect (
The host='localhost',
Port='3306',
User='root',
Passwd='123456',
The db='June 18 years data detail,
Charset='utf8'
)
# connect cursor
Cursor=connect. Cursor ()
# SQL statement
SQL="select clients subsidiary June _18. Customer from the customer detail _18 year June where customer detail June _18. Group='% s'" % (' B - 3 Yang Zhongkui)
# executing SQL statements
Cursor. The execute (SQL)
Results=cursor. Fetchall ()
For r in the results:
Print (" r ")


Error the following
C: \ Users \ admin \ PycharmProjects \ untitled \ venv \ Scripts \ python exe C:/Users/admin/PycharmProjects/untitled/venv/test
Traceback (the most recent call last) :
The File "C:/Users/admin/PycharmProjects/untitled/venv/test", line 8, the in & lt; module>
Charset='utf8'
File "C: \ Users \ admin \ PycharmProjects \ untitled \ venv \ lib \ site - packages \ pymysql \ set py", line 94, in the Connect
Return the Connection (* args, * * kwargs)
The File "C: \ Users \ admin \ PycharmProjects \ untitled \ venv \ lib \ site - packages \ pymysql \ connections py", line 327, in __init__
The self. The connect ()
The File "C: \ Users \ admin \ PycharmProjects \ untitled \ venv \ lib \ site - packages \ pymysql \ connections py", line 588, in the connect
Self. Host_info="socket % s: % d" % (self. The host, the self. The port)
TypeError: % d format: a number is required, not STR

CodePudding user response:

Try this way:

 
The config={
'host' : '127.0.0.1,
'the port: 3306,
'user' : 'root',
'password' : 'xinxin2333',
'database' : 'trade_ms',
'charset' : 'utf8mb4',
'cursorclass: pymysql. Your cursors. Cursor,
}

# connect to the database
Connection=pymysql. Connect (* *)

CodePudding user response:

Hello, behind the port with the Numbers, you give the string, modify the port=3306 rather than the port="3306"
  • Related