How are we doing? Please help us improve Stack Overflow. Take our short survey

Questions tagged [pymysql]

PyMySQL is a database connector for Python like MySQLdb.

Filter by
Sorted by
Tagged with
71 votes
20 answers
217k views

No module named 'pymysql'

I'm trying to use PyMySQL on Ubuntu. I've installed pymysql using both pip and pip3 but every time I use import pymysql, it returns ImportError: No module named 'pymysql' I'm using Ubuntu 15.10 64-...
  • 1,315
68 votes
3 answers
58k views

Pymysql Insert Into not working

I'm running this from PyDev in Eclipse... import pymysql conn = pymysql.connect(host='localhost', port=3306, user='userid', passwd='password', db='fan') cur = conn.cursor() print "writing to db" cur....
  • 1,643
49 votes
7 answers
87k views

Using python to write mysql query to csv, need to show field names

I have the following: import MySQLdb as dbapi import sys import csv dbServer='localhost' dbPass='supersecretpassword' dbSchema='dbTest' dbUser='root' dbQuery='SELECT * FROM pbTest.Orders;' db=...
  • 945
48 votes
5 answers
56k views

What is PyMySQL and how does it differ from MySQLdb? Can it affect Django deployment?

I just solved some problems in my Django 1.3 app by using PyMySQL instead of MySQLdb. I followed this tutorial on how to make the switch: http://web-eng-help.blogspot.com/2010/09/install-mysql-5-for-...
  • 4,117
31 votes
4 answers
142k views

How to insert data to django database from views.py file?

How can I insert data to my django database from a function in the views,py file? Is python manage.py shell the only way to insert? For more explanations I'm using: python 3.4 django 1.8.2 PyMySQL ...
  • 2,138
22 votes
1 answer
24k views

Using SQLAlchemy and pymysql, how can I set the connection to utilize utf8mb4?

I discovered (the hard way) that MySQL's UTF8 character set is only 3 bytes. A bit of research shows I can fix this by changing the tables to utilize the utf8mb4 collation and get the full 4 bytes UTF ...
  • 47.4k
22 votes
2 answers
19k views

aiohttp+sqlalchemy: Can't reconnect until invalid transaction is rolled back

I'm using aiohttp and sqlalchemy, and I've created a Singleton that helps me to connect when I'm needed a instance of SQLAlchemy (code follows). Unfortunately, every once in awhile I get the following ...
  • 5,993
20 votes
2 answers
19k views

How to config Django using pymysql as driver?

I'm new to Django. It wasted me whole afternoon to config the MySQL engine. I am very confused about the database engine and the database driver. Is the engine also the driver? All the tutorial said ...
  • 311
20 votes
1 answer
27k views

pyMySQL set connection character set

I'm developing a fairly straightforward web app using Flask and MySQL. I'm struggling with unicode. Users sometimes paste stuff that they copied from Word and it's falling over with the old smart ...
  • 3,213
19 votes
1 answer
21k views

Python3 mysqlclient-1.3.6 (aka PyMySQL) usage?

Im still very much learning python and all the different ways to use 3rd party modules. I have installed https://pypi.python.org/pypi/mysqlclient which was recommended here Python 3 and MySQL I ...
  • 1,279
18 votes
2 answers
26k views

Mock a MySQL database in Python

I use Python 3.4 from the Anaconda distribution. Within this distribution, I found the pymysql library to connect to an existing MySQL database, which is located on another computer. import pymysql ...
17 votes
2 answers
33k views

PyMysql UPDATE query

I've been trying using PyMysql and so far everything i did worked (Select/insert) but when i try to update it just doesn't work, no errors no nothing, just doesn't do anything. import pymysql ...
  • 1,325
17 votes
6 answers
23k views

Python mysql (using pymysql) auto reconnect

I'm not sure if this is possible, but I'm looking for a way to reconnect to mysql database when the connection is lost. All the connections are held in a gevent queue but that shouldn't matter I think....
17 votes
1 answer
3k views

PyMySQL returning old/snapshot values/not rerunning query?

I'm using pymysql.cursors and a simplified code example that loads a row from a table and prints it every second is: #!/usr/bin/env python3 import pymysql.cursors import time conn = pymysql.connect(...
  • 19.9k
16 votes
2 answers
51k views

Select query in pymysql

When executing the following: import pymysql db = pymysql.connect(host='localhost', port=3306, user='root') cur = db.cursor() print(cur.execute("SELECT ParentGuardianID FROM ...
16 votes
3 answers
8k views

Can I use pymysql.connect() with "with" statement?

The following is listed as example in pymysql: conn = pymysql.connect(...) with conn.cursor() as cursor: cursor.execute(...) ... conn.close() Can I use the following instead, or will this ...
15 votes
3 answers
24k views

How to store mySQL query result into pandas DataFrame with pymysql?

I'm trying to store a mySQL query result in a pandas DataFrame using pymysql and am running into errors building the dataframe. Found a similar question here and here, but it looks like there are ...
15 votes
2 answers
23k views

How to get rows affected in a UPDATE statement by PyMySQL?

I need to update some rows on the MySQL database by PyMYSQL and I want to know how many rows had been changed. import pymysql db = pymysql.connect(xxxx) cur = db.cursor() sql = "update TABLE set ...
  • 151
14 votes
1 answer
23k views

PyMySQL Insert NULL or a String

I tried to insert a field (title) with PyMySQL that can be NULL or a string. But it doesn't work. query = """ INSERT INTO `chapter` (title, chapter, volume) VALUES ("%s", "%s", %d) """ cur....
  • 1,756
14 votes
3 answers
20k views

How can I escape the input to a MySQL db in Python3?

How can I escape the input to a MySQL db in Python3? I'm using PyMySQL and works fine, but when I try to do something like: cursor.execute("SELECT * FROM `Codes` WHERE `ShortCode` = '{}'".format(...
14 votes
4 answers
17k views

pymysql.err.InterfaceError: (0, '') error when doing a lot of pushes to sql table

I am doing a lot of inserts to a mysql table in a short period of time from python code (using pymysql) that uses a lot of different threads. Each thread, of which there are many, may or may not end ...
14 votes
2 answers
17k views

What exceptions could be returned from Pandas read_sql()

I have a user-defined function that uses pymysql to connect to a mysql database and then it interrogates the database and reads the results into a Pandas dataframe. import pandas as pd import pymysql ...
  • 3,960
13 votes
3 answers
4k views

Command 01_migrate failed on Amazon Linux 2 AMI

I have a Django project which is deployed to Elastic Beanstalk Amazon Linux 2 AMI. I installed PyMySQL for connecting to the db and i added these lines to settings.py such as below; import pymysql ...
13 votes
2 answers
10k views

How do I configure PyMySQL connect for SSL?

I'm trying to connect my database using SSL with PyMySQL, but I can't find good documentation on what the syntax is. These credentials work in Workbench and with the CLI, but I get this error when ...
13 votes
2 answers
2k views

PyMySQL different updates in one query?

So I have a python script that goes through roughly 350,000 data objects, and depending on some tests, it needs to update a row which represents each one of those objects in a MySQl db. I'm also using ...
  • 38.4k
12 votes
3 answers
38k views

How to get the MySQL type of error with PyMySQL?

I'm doing a Python application with MySQL and PyMySQL and I'd like to be able to know the number of the MySQL error when I get one so that I can do something different depending on it. Is there a way ...
  • 799
12 votes
5 answers
23k views

pyMySQL: How to check if connection is already opened or close

I am getting the error InterfaceError (0, ''). Is there way in Pymysql library I can check whether connection or cursor is closed. For cursor I am already using context manager like that: with ...
  • 13.5k
12 votes
2 answers
15k views

How can I do begin transaction in pymysql ? (mysql)

I want to use run below mysql script using with pymysql. START TRANSACTION; BEGIN; insert into ~~~ COMMIT; my python source code is connection = pymysql.connect(~~~~~~~) with connection....
  • 765
11 votes
4 answers
16k views

TypeError: _init_() takes 1 positional argument but 5 were given

This is the Python code where I am establishing a database connection. But I am getting a type error in my code. Please tell me what is the issue. import pymysql connnection = pymysql.connect("...
11 votes
1 answer
2k views

PyMySQL and OrderedDict

I've been using PyMySQL for a while now and created my own wrapper that I'm used to to shorthand writing queries. Nonetheless I've been creating CSV files with OrderedDict because I need to keep the ...
  • 2,685
11 votes
1 answer
18k views

Is connection.commit() needed after each cursor.execute()?

Is it a valid PyMySQL operation to cursor.execute(…) multiple times before executing connection.commit(), or does connection.commit() need to occur after each execute statement for the results to be ...
  • 2,155
11 votes
2 answers
13k views

PyMySQL throws 'BrokenPipeError' after making frequent reads

I have written a script to help me work with a database. Specifically, I am trying to work with files on disk and add the result of this work to my database. I have copied the code below, but removed ...
11 votes
1 answer
2k views

Intermittently can't connect to mysql on AWS RDS (Error 2003)

We are having an intermittent issue with connections to our mysql server timing out. The error we are receiving is as following. (2003, 'Can\'t connect to MySQL server on \'<connection>\' ((...
  • 141
10 votes
1 answer
6k views

Python, sharing mysql connection in multiple functions - pass connection or cursor?

I am opening mysql connection in the main function and use that connection in multiple functions called by the main function. Is there anything wrong with passing cursor from main function instead of ...
10 votes
1 answer
11k views

MySQL connection pool in python?

I'm trying to process large amount of data using Python and maintaining processing status in MySQL. However, I'm surprised there is no standard connection pool for python-mysql (like HikariCP in Java)....
  • 1,339
9 votes
2 answers
6k views

Cannot connect to a local mysql db with sqlalchemy on windows machine

I'm trying to connect to a local mysql DB on my windows machine using sqlalchemy. It works using pymysql, but not with sqlalchemy. Code sqlalchemy: engine = create_engine('mysql+mysqldb://root:...
  • 323
9 votes
2 answers
12k views

PyMySQL Warning: (1366, "Incorrect string value: '\\xF0\\x9F\\x98\\x8D t...')

I'm attempting to import data (tweets and other twitter text information) into a database using Pandas and MySQL. I received the following error: 166: Warning: (1366, "Incorrect string value: '\xF0\...
9 votes
5 answers
15k views

Python to mysql 'Timestamp' object has no attribute 'translate'

I'm trying to load a pandas dataframe to a mysql table using Sqlalchemy. I connect using; engine = create_engine("mysql+pymysql://user:password@ip:port/db") I am then simply running; df.to_sql(con=...
9 votes
3 answers
3k views

Can't connect to Cloud SQL using PyMySQL

I'm trying to connect to Cloud SQL from a Python application (using PyMySQL 0.7.9) running on top of Google App Engine. My connection string looks like this (credentials are fake of course): pymysql....
  • 8,358
8 votes
4 answers
9k views

Error while using pymysql in flask

I am using pymysql client to connect to mysql in my flask API, everything works fine for some days(around 1-2 days) after that suddenly it starts to throw this error Traceback (most recent call last)...
  • 657
8 votes
2 answers
7k views

PyMySQL unable to execute multiple queries

Using the latest version of PyMySQL(0.9.3) I am unable to execute a query string which has multiple SQL statements in it separated by a semicolon(;) My python version is: Python 3.6.5 import pymysql ...
  • 251
8 votes
2 answers
19k views

Fetch data with pymysql (DictCursor)

It seems like a really simple task but I'm having difficulties doing it proper. My SQL Query look like this: self.link = self.db.cursor(pymysql.cursors.DictCursor); self.link.execute("SELECT * FROM ...
  • 9,675
8 votes
2 answers
1k views

pymysql stopped working : NameError: name 'byte2int' is not defined

I am using pymysql in Python to connect to database. It was working fine but now I am getting following error : Traceback (most recent call last) : File "/Users/njethani/Desktop/venv/lib/python3....
  • 119
8 votes
1 answer
6k views

pymysql lost connection after a long period

using pymysql connect to mysql, leave the program running for a long time,for example, leave the office at night and come back next morning.during this period,no any operation on this application.now ...
  • 4,009
8 votes
1 answer
4k views

flask-login without flask-sqlalchemy or ORM

I am currently using flask-login in my application for user login session management. I am using flask-sqlalchemy, so all working ok. Because of my previous sql experience, I am not fan of ORM. I like ...
  • 104
7 votes
3 answers
14k views

Pandas read_sql() - AttributeError: 'Engine' object has no attribute 'cursor'

I am trying to read data from MySQL query using pandas read_sql() method with python3+sqlalchemy+pymysql I tried to follow the following tutorials - https://pythondata.com/quick-tip-sqlalchemy-for-...
  • 377
7 votes
1 answer
5k views

How to ignore pymysql warnings?

Consider this code: import pymysql db= pymysql.connect("localhost","root","","raspi") cursor = db.cursor() cursor.execute("INSERT INTO access(username)VALUES('hello')") db.commit() db.close() when ...
7 votes
1 answer
11k views

Inserting a list holding multiple values in MySQL using pymysql

I have a database holding names, and I have to create a new list which will hold such values as ID, name, and gender and insert it in the current database. I have to create a list of the names which ...
7 votes
1 answer
4k views

SSL Certification Error > hostname doesn't match

I'm trying to connect to Google Cloud MYSQL server using SSL certificates and the python module PyMySQL with the following line: connection = pymysql.connect(host=os.environ['SQL_HOST_IP'], user=os....
7 votes
3 answers
15k views

How to check the status of a mysql connection in python?

I am using pymysql to connect to a database. I am new to database operations. Is there a status code that I can use to check if the database is open/alive, something like db.status.
  • 2,075

1
2 3 4 5
27