pymysql

ModuleNotFoundError - PyMySQL for python 3

北城以北 提交于 2019-12-11 15:57:48
问题 I am trying to get a simple test program working on my machine that connects to a SQL DB. I pip installed and then uninstalled and then installed with pip3: pymysql. the issue I'm getting: import PyMySQL ModuleNotFoundError: No module named 'PyMySQL'. it can be found when i run the command pip list, but not found when running the program itself. I was perusing over other SO Q&A's but nothing helped. Thanks 回答1: First insall PyMySQL using: pip install PyMySQL In python 3 it is pymysql , all in

Python (PyMySQL) SELECT query returning boolean, not desired value

ε祈祈猫儿з 提交于 2019-12-11 08:20:07
问题 I am using PyMySQL with Python to access my database. (MySQLdb is not yet available for newer releases of Python.) This is my query: cur = db.cursor() cur.execute("SELECT ingredientID FROM Ingredients WHERE ingredientName = %s", "onions") However, instead of returning the ingredientID , a boolean is returned stating the recipe was found. I have worked with MySQL(i) in PHP and have not had this issue occur in the past. 回答1: You need to somehow fetch the result of the query: cur = db.cursor()

pymysql return error SQL syntax

人走茶凉 提交于 2019-12-11 04:47:44
问题 On py3, i use pymysql module for connecting to MySQL. i write function into Database() class like this where MySQLi run on constructor: def add_user_to_database(self, id, first_name, last_name, username, lang_code): with self.MySQLi.cursor() as cursor: cursor.execute('INSERT INTO users (id, first_name, last_name, username, language_code) VALUES ({0}, {1}, {2}, {3}, {4})'.format(id, first_name, last_name, username, lang_code)) connection.commit() after i run py database.php it show this error

Error No Module named “PyMySQL” Windows 10

为君一笑 提交于 2019-12-11 03:28:15
问题 i have problem to try pymysql. my computer is using windows 10 use python 3.5 i have installed pymysql via pip install pymsql and success, no error. i have checked with pip list and get PyMySQL (0.7.9) but when i run import PyMySQL get error no module named "PyMySQL" where is the problem? edited : but if i try import pymysql , i got error : Traceback (most recent call last): File "pymysql1.py", line 1, in <module> import pymysql File "C:\Program Files (x86)\Python35-32\lib\site-packages

How to get a result from multiple select statements with pymysql

六眼飞鱼酱① 提交于 2019-12-11 00:29:58
问题 Basically, I have the following example (Assume cur comes from a valid connection): >>> con = pymysql.connect(<parameters go here>) >>> cur = con.cursor() >>> sql = "SELECT @a := 0; SELECT @a := @a+2; SELECT @a;" >>> res = cur.execute(sql) >>> res 1 As you can see, res returns the integer 1, which means the sql went well. However, the last select should return the number 2 and I need that number. If I run this code (suggested by @falsetru), I don't get what I need either: >>> cur.execute(sql)

python实现接口自动化测试中如何使用pymysql直连数据库?

对着背影说爱祢 提交于 2019-12-10 18:38:07
概述 接口测试中,我们PyMySQL是纯 Python 实现的驱动,速度上不理想,但最大的特点可能就是它的安装方式没那么繁琐,是 python 直连数据库时常用的第三方库 理论基础+典型应用场景,巧用python轻松搞定接口自动化测试 实现步骤 1 PyMySQL 安装 启动命令行,联网的前提下键入命令: pip install pymysql 2 PyMySQL 基本实现流程简介 导入第三方 import pymysql 创建连接,配置连接信息 conn = pymysql.Connect(host=“127.0.0.1”, port=3306, database=“books”, user=“root”, password=“root”, charset=“utf8”) 创建数据操作载体对象_ cursor 游标 cursor = conn.cursor() 按照需求,编写并执行 sql 语句 首先,声明 SQL 语句 sql = “select * from t_book” 然后,通过 cursor 对象将 SQL 语句发送到数据库 cursor.execute(sql) 最后,通过 cursor 对象获取响应结果 print(“行数:”,cursor.rowcount)#获取行数 print(“第一条:”,cursor.fetchone())# 获取单条数据 最后释放资源

python3 sqlalchemy pymysql connect string

安稳与你 提交于 2019-12-10 17:28:14
问题 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', port='3333') cur = conn.cursor() cur.execute('select user from auth_users') for i in cur: print(i) trying to get sqlalchemy to connect with pymysql, the default example strings don't seem to work. the above example does not work unless I declare both

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

守給你的承諾、 提交于 2019-12-10 15:24:10
问题 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 + pymysql.install_as_MySQLdb() +except ImportError: + pass but get error: /local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 30, in <module> from MySQLdb.converters import conversions, Thing2Literal ImportError: cannot import name Thing2Literal how to

Unable to make TLS TCP connection to remote MySQL server with PyMySQL, other tools work

拟墨画扇 提交于 2019-12-10 11:50:01
问题 Setting up a new server that I want to communicate to a central MySQL database, using a TLS connection for security Following steps like this I have been able to set up TLS for my MySQL server, I have made several users that are able to login from any host (%), and require SSL connections +------------+-----------+----------+ | user | host | ssl_type | +------------+-----------+----------+ | testuser | % | ANY | +------------+-----------+----------+ I can confirm this on any host by

Pymysql cant connect Amazon RDS host, but same host is accessible through mysql workbench

巧了我就是萌 提交于 2019-12-10 10:50:34
问题 I am using pymysql to connect to Amazon RDS and it fails with : db = pymysql.connect(host=Host, user=User, password=Pswd, db=DBN, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor,local_infile=True) File "/usr/local/lib/python2.7/dist-packages/pymysql/err.py", line 107, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.OperationalError: (1045, u"Access denied for user 'p_cs'@'xx.xx.xx.xx' (using password: YES)") However If i try to connect to the same host with