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
73
votes
20 answers

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-bit and Python 3.5. The same .py works on Windows…
troyz
  • 1,345
  • 2
  • 11
  • 19
69
votes
3 answers

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.execute("INSERT INTO cbs_transactions(leagueID)…
Michael T
  • 1,745
  • 5
  • 30
  • 42
51
votes
7 answers

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…
Mathnode
  • 965
  • 1
  • 9
  • 15
48
votes
5 answers

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-python-26-and.html Now I want to know what PyMySQL…
Hafiz
  • 4,187
  • 12
  • 58
  • 111
32
votes
4 answers

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 For example: models.py: from django.db import…
niloofar
  • 2,244
  • 5
  • 23
  • 44
24
votes
1 answer

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 should be. I've done so. My database, tables and…
Andy
  • 49,085
  • 60
  • 166
  • 233
22
votes
2 answers

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 error (which I "solve" by restarting the…
Yam Mesicka
  • 6,243
  • 7
  • 45
  • 64
22
votes
2 answers

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 that the ENGINE should be…
zhy1378
  • 329
  • 1
  • 2
  • 7
20
votes
1 answer

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 quotes u'\u201c'. A little bit of investigation shows…
MalphasWats
  • 3,255
  • 6
  • 34
  • 40
19
votes
1 answer

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 believe i installed the package correctly…
Justin S
  • 1,409
  • 4
  • 22
  • 38
19
votes
2 answers

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 config = { 'user': 'my_user', 'passwd':…
physicalattraction
  • 6,485
  • 10
  • 63
  • 122
19
votes
6 answers

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. I'm sure if I put some time in, I can come up…
18
votes
6 answers

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 up pushing data to a MySql table. Here is the…
sometimesiwritecode
  • 2,993
  • 7
  • 31
  • 69
18
votes
1 answer

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(host='localhost', # credentials etc. …
artfulrobot
  • 20,637
  • 11
  • 55
  • 81
18
votes
2 answers

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 connection = pymysql.connect(...) cursor =…
Shay
  • 1,375
  • 5
  • 16
  • 26
1
2 3
91 92