Questions tagged [pymysql]

PyMySQL is a database connector for Python like MySQLdb.

PyMySQL is a database connector for Python, that means it is a library to enable Python programs to talk to a MySQL server.

It is written in pure Python and works with Python 2.7+ and Python 3.X.

pymysql is a drop-in replacement for mysqldb.

Documentation can be found at https://pymysql.readthedocs.io/

1369 questions
4
votes
1 answer

How to return the last primary key after INSERT in pymysql (python3.5)?

CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `email` varchar(255) COLLATE utf8_bin NOT NULL, `password` varchar(255) COLLATE utf8_bin NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8…
xaero
  • 215
  • 1
  • 2
  • 6
4
votes
2 answers

How do I import a MySQL database in a Python script?

I've seen some similar questions about this on StackOverflow but haven't found an answer that works; see http://stackoverflow.com/questions/4408714/execute-sql-file-with-python-mysqldb AND…
ProgrammingWithRandy
  • 725
  • 3
  • 14
  • 31
4
votes
1 answer

pymysql query formatting, TypeError: %d format: a number is required, not str

So I was writing a sql query to get data from the database using python pymysql library. The user will enter a year as a text field in HTML form and display the data associated with this year. I'm using this code and I'm keep getting error for it.…
jondoyle
  • 53
  • 1
  • 3
4
votes
2 answers

is PyMySQL well supported? and is it slower than than MySQLdb?

I'm building a python3 app which requires high-speed connections. Being a pure python library, will PyMySQL be significantly slower than the C based MySQLdb in connecting and executive queries? Is PyMySQL well supported for future versions of…
wolfgang
  • 7,281
  • 12
  • 44
  • 72
4
votes
1 answer

Python3: Does mysql db connection need to be explicitly closed in function?

Do you have to close mysql (pymysql) connection explicitly within a function in python3, or can you let python3 take care of it automatically as it gets out of scope.
Paul Grant
  • 41
  • 1
4
votes
0 answers

PyMySQL AssertionError: Result length not requested length

I have a Python 3.4 application in beta that I am testing that uses PyMySQL 0.6.3 to connect to MySQL. I have been getting occassional errors, AssertionError: Result length not requested length. It is a multi-threaded application and this post…
postelrich
  • 3,274
  • 5
  • 38
  • 65
4
votes
2 answers

At what point is MySQL primary key error thrown?

If I have a batch insert statement like: INSERT INTO TABLE VALUES (x,y,z),(x2,y2,z2),(x3,y3,z3); And x2 violates a primary key, is the error thrown before or after the processing of x3? Specifically, I have a bunch of batch inserts in a try-catch…
Tommy
  • 12,588
  • 14
  • 59
  • 110
4
votes
3 answers

Unable to Insert into MySQL via Python and pymysql

I've got a table with 9 columns, the first three are all text and the last 6 are setup as INT's. When I insert into the text fields everything works as expected conn = pymysql.connect(host='', port=, user='', passwd='', db='') cur =…
Peter Foti
  • 5,526
  • 6
  • 34
  • 47
3
votes
1 answer

pymysql callproc() appears to affect subsequent selects

I'm attempting to transition a code base from using MySQLdb to pymysql. I'm encountering the following problem and wonder if anyone has seen something similar. In a nutshell, if I call a stored procedure through the pymysql cursor callproc()…
Paul Joireman
  • 2,689
  • 5
  • 25
  • 33
3
votes
1 answer

Python: Error with mysql.connector and SSL, but works with pymysql.connect

For a project I need to make a change to existing code for supporting a MySQL connection using SSL certificates. The implemented package is mysql.connector and is heavily integrated in other parts of the source-code, so replacing it with pymysql…
telefoontoestel
  • 357
  • 1
  • 2
  • 14
3
votes
0 answers

mysql 1300 Invalid utf8mb4 character string: '\\xF0\\x9F\\x91\\x8C' with Unicode emoji

So I'm trying to commit unicode emoji to database (this one especially:) But everytime something with emoji is executed on database this happens: pymysql.err.OperationalError: (1300, "Invalid utf8mb4 character string: '\\xF0\\x9F\\x91\\x8C'") I've…
Moder New
  • 457
  • 1
  • 5
  • 18
3
votes
1 answer

Rollback multiple queries in PyMySQL

A similar question to this has been posted but unfortunately none of the suggested solutions worked for me. I wanted to see if I could write two queries in one try clause and have them both rollback if one of them threw an exception. In order to…
Bloop
  • 53
  • 7
3
votes
0 answers

SqlAlchemy / PyMySQL: AttributeError: module 'socket' has no attribute 'AF_UNIX' on Windows

So I think I know where this error comes from. I'm using query_string = dict({"unix_socket": "/cloudsql/{}".format(connection_name)}) as my connection string, as per the tutorial I followed. However, in my searches I found that Python doesn't…
3
votes
2 answers

pd.read_sql - Unsupported format character error (0x27)

As above, I'm trying to use pd.read_sql to query our mysql database, and getting an error for double/single quotes. When I remove the % operators from the LIKE clause (lines 84-87) the query runs, but these are needed. I know I need to format the…
3
votes
0 answers

PyMySQL Cannot Replace Variable in Statement When Executing SQL

I'm somewhat stuck here. I'm using Python 3.9.0 with PyMySQL (0.10.1) and trying to create a function that creates a table. Every time I run the following statement: table = 'test' cursor = db.cursor() statement = """CREATE…
Marko Bajlovic
  • 323
  • 5
  • 12