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
5
votes
3 answers

mysql Access denied for user root@localhost (using password: NO) despite having set a password and entered it in connection uri

I'm trying to configure a mysql db with pymysql and Flask-sqlalchemy in a flask app. db = SQLAlchemy() app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:password@localhost:3306/ftm' db.init_app(app) However, when I run my app, I…
Toby Weed
  • 594
  • 2
  • 7
  • 20
5
votes
1 answer

Is pymysql connection thread safe? Is pymysql cursor thread safe?

I have a queue data structure where multiple threads consume items, each thread is going to write to a database using PyMySQL, no other sync is needed among threads. Is it race free to use the same cursor coming from the same pymysql connection in…
5
votes
1 answer

PyMySQL with Django, Multithreaded application

We are trying to use PyMySQL (==0.7.11) in our Django (==1.11.4) environment. But we are encountered with problems when multiple actions are performed at the same time (Multiple requests sent to the same API function). We get this…
Emanuel
  • 640
  • 1
  • 7
  • 25
5
votes
1 answer

Port 3306 not listening? Can't connect to MySQL remotely

I'm trying to connect to MySQL remotely with pymysql and I'm getting the error message: (2003, "Can't connect to MySQL server on 'ip address' ([WinError 10061] No connection could be made because the target machine actively refused it)") In my…
5
votes
1 answer

MySQL 'SHOW TABLES' Returns count instead of list (Python)

I'm troubleshooting a script I am using to query the database. To make sure I had everything working right I stripped it down to a simple 'SHOW TABLES' query. The problem is that it is returning a count of the tables instead of the list of names it…
Joe
  • 2,641
  • 5
  • 22
  • 43
5
votes
4 answers

Reading .sql File in for Execution in Python (pymysql)

I'm attempting to create a multiscript tool, that will take an argument of a .sql file and execute it. I've set up a simple test, just executing on one database, however the syntax is giving me issues every time. DELIMITER $$ CREATE…
Jacob
  • 359
  • 1
  • 4
  • 13
5
votes
1 answer

Why do JSON queries return object if there is one element, list if more than one?

I had to rewrite a python script from python2 to python 3 to solve the encoding problems I had the easiest way. I had to move from mysqldb to pymysql which seemed to use same syntax. I accessed the pymysql's github[1] site and following examples I…
XiR_
  • 222
  • 1
  • 8
5
votes
1 answer

Use Python list in SQL query for column names

I have a bunch of column names in a Python list. Now I need to use that list as the column names in a SELECT statement. How can I do that? pythonlist = ['one', 'two', 'three'] SELECT pythonlist FROM data; So far I have: sql = '''SELECT %s FROM…
LK27
  • 53
  • 1
  • 6
5
votes
4 answers

How to copy a database with mysqldump and mysql in Python?

I am writing a simple Python script to copy a MySQL database. I am attempting to copy the database based on the following SO questions and their answers: "Copy/duplicate database without using mysqldump", "python subprocess and mysqldump" and…
PJvG
  • 1,310
  • 3
  • 16
  • 33
5
votes
1 answer

Proper way to use PyMySql in a memory efficient generator

I want to write a generator function that will run on a memory limited system that uses PyMySql (or MySQLDb) to return the results of a select query one at a time. The following works: #execute a select query and return results as a generator def…
Tommy
  • 12,588
  • 14
  • 59
  • 110
5
votes
1 answer

Impossible to insert data with PyMySQL when I use parameter

I'm currently working on a basic query which insert data depending on the input parameters, and I'm unable to perfom it. cur.execute("INSERT INTO foo (bar1, bar2) values (?, ?)", (foo1, foo2)) I have this error message: Exception in Tkinter…
gaetanm
  • 1,394
  • 1
  • 13
  • 25
5
votes
2 answers

django 1.5 + pymysql error: ImportError: cannot import name Thing2Literal

I try to use django1.5 and pymysql as MySQLdb as here How to make Django work with unsupported MySQL drivers such as gevent-mysql or Concurrence's MySQL driver? In the top of my management command: +try: + import pymysql + …
Evg
  • 2,978
  • 5
  • 43
  • 58
5
votes
3 answers

Installing PyMySQL on a Windows 7 machine

I am not a python user and though I have used MySQL, I'm not an expert. Also, I'm mainly a Windows user and I don't know much about running command line scripts. So this might be a stupid question but I want to ask anyway... (BTW my purpose is to…
Michael T
  • 1,745
  • 5
  • 30
  • 42
5
votes
2 answers

python3 sqlalchemy pymysql connect string

using python3, I can connect to mysql using pymysql. all works as expected. enclosed code works. import pymysql conn = pymysql.connect(host='127.0.0.1', unix_socket='/home/jhgong/mysql/tmp/mysql.sock', user='root', passwd='my_pass', db='my_db',…
Jeff Gong
  • 51
  • 1
  • 1
  • 2
4
votes
0 answers

Limit Length of Query Error Prints with SQLAlchemy / PyMySQL

I'm using SQLAlchemy 1.3.22 and doing a bulk insert of thousands of rows. If there is a database error the SQLAlchemy ProgrammingError exception that gets raised in the console prints the query and all of the values. Even though I'm chunking the…
totalhack
  • 2,298
  • 17
  • 23