pymysql

Python/MySQL execute in for gives error:- TypeError: 'int' object is not iterable

折月煮酒 提交于 2019-12-13 10:29:40
问题 I get the following error when I execute cursor in for loop. Traceback (most recent call last): File "mysql_select_query.py", line 35, in <module> for row in cur.execute(sql_select): TypeError: 'int' object is not iterable Here is my code that gives error: sql_select = "SELECT * FROM T_EMP" for row in cur.execute(sql_select): print("{}, {}, {}, {}".format(row[0], row[1], row[2], row[3])) It works well when I execute & use fetchall(): sql_select = "SELECT * FROM T_EMP where ID>%s" rows = cur

B-02 Django-第二部分(熟练掌握)-模型(Model)设计-数据库配置(基础)

两盒软妹~` 提交于 2019-12-13 06:18:06
Django-第二部分(熟练掌握)-模型(Model)设计-数据库配置(基础) 文章目录 Django-第二部分(熟练掌握)-模型(Model)设计-数据库配置(基础) 目标 回顾 a、模型(Model)设计流程过程说明 一、配置使用sqlite 1.1、配置方法 1.2、常见问题 1.2.1、子串匹配和区分大小写 1.2.2、“数据库被锁定”错误 二、配置使用mysql 2.1、配置方法 第一步:修改工程目录下的__init__.py 文件 第二步:修改setting.py文件 2.2、常见问题 问题一、No module named 'MySQLdb' 错误提示 问题原因 解决办法 问题二、mysqlclient 1.3.3 or newer is required 错误提示 问题原因 解决办法 问题三、decode错误 三、配置使用Oracle 3.1、配置方法 3.2、常见问题 目标 前面已经介绍了如何快速入门,现在开始熟练掌握一些知识 知道在哪了进行数据库的配置并进行基本的配置 了解配置过程中常见的问题 回顾 a、模型(Model)设计流程过程说明 第一步-配置使用数据库 第二步-定义模型类 第三步-迁移数据 第四步-访问使用数据 一、配置使用sqlite Django支持SQLite 3.8.3及更高版本。 1.1、配置方法 说明:Django默认使用 SQLite

AttributeError: 'NoneType' object has no attribute 'encoding' using pymysql

僤鯓⒐⒋嵵緔 提交于 2019-12-13 04:10:07
问题 import pymysql conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123456',db='home', charset="utf-8") cursor = conn.cursor() cursor.execute("""create table job_list(job varchar(30) , people varchar(30) , catagory varchar(30) , place varchar(30), publish varchar(30)) """) try: cursor.execute("""INSERT INTO job_list(job,people,catagory,place,publish) VALUES (%s, %s, %s, %s, %s)""", ["算法工程师", "2018毕业生", "研发", "雅加达", "2018-03-28"]) conn.commit() except pymysql.Error as e:

How to remove extra quotes in pymysql

谁说胖子不能爱 提交于 2019-12-13 03:06:13
问题 This code uses pymysql, however when i try to insert the variable title into the sql query it comes out with 'title' for example when i set title to = test the database created is 'test' is there a way to create the table without the extra quotes import pymysql connection = pymysql.connect( host='localhost', user='root', password='', db='comments', ) c= connection.cursor() sql ='''CREATE TABLE IF NOT EXISTS `%s` ( `comment_id` int(11) NOT NULL, `parent_comment_id` int(11) NOT NULL, `comment`

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

爷,独闯天下 提交于 2019-12-12 14:13:27
问题 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 DEFINER=`a_user`@`%` PROCEDURE `a_procedure`( IN DirectEmployeeID TEXT, IN StartRange DATE, IN EndRange DATE ) BEGIN SELECT aColumn WHERE thisThing = 1; END$$ DELIMITER ; To be clear, this script has been tested, and works when passed like : mysql -uuser -p -hhost

Flask-SQLAlchemy PyMySQL - Access Denied Error

南楼画角 提交于 2019-12-12 04:15:46
问题 OS: RHEL Python Version: 3.6 SQLAlchemy Version: 1.1.10 PyMySQL Version: 0.7.11 MySQL Distrib: 5.7.17-13 import pymysql conn = pymysql.connect(host='localhost', port=3306, user='testuser', passwd='###########', db='mysql') cur = conn.cursor() cur.execute("SELECT Host,User FROM user") print(cur.description) print() for row in cur: print(row) cur.close() conn.close() When I try to execute the above code I'm getting the following error message, but I'm still able to connect to mysql using the

Why can't replace placeholder with format function in pymysql?

我只是一个虾纸丫 提交于 2019-12-12 01:05:35
问题 How i create the table mingyan . CREATE TABLE `mingyan` ( `tag` varchar(10) DEFAULT NULL, `cont` varchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; It's said that string format function with {} is more pythonic way than placeholder % . In my scrapy to write some fields into a table mingyan . self.cursor.execute("insert into mingyan(tag, cont) values (%s, %s)",(item['tag'],item['cont'])) It works fine in my scrapy,now i replace the placeholder way with string format function. self

Lost connection to MySQL server during query - Python 3.x - pymysql

巧了我就是萌 提交于 2019-12-11 18:53:00
问题 I'm trying to connect to a server to fetch details from one of the databases using pymysql library in python. But I keep getting this same error and I've no clue on why. I'm pretty new to Python and hoping someone could help me here. I tried checking the post here but not very helpful. Here is my code. import pymysql print("Connecting mysql") connection = pymysql.connect(host=A.B.C.D,user='admin',password='admin',db='MY_DB',port=ABCD) and here is the error I get Connecting mysql Traceback

ImportError: No module named pymysql in python 2.7

谁说胖子不能爱 提交于 2019-12-11 17:19:11
问题 I have flask web application running on aws, my app.py file gives error for "import pymysql" line (whole application is working fine.) Error.log [Sat Jul 29 06:12:54.545904 2017] [wsgi:error] [pid 28317:tid 140546426812160] [client ] ImportError: No module named pymysql Python version is - 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] I created test.py file and executed, it worked and displays rows from database which is on RDS , So no idea why same thing is not working on app

What is syntactically wrong with this ON DUPLICATE KEY UPDATE query?

早过忘川 提交于 2019-12-11 16:27:52
问题 Update: This issue was resolved in the comments and is awaiting an answer When executing the following query in PyMySQL, I receive the error ‘ 1064, u"You have an error in your SQL syntax; ’ (full error message below) INSERT INTO `table_name` (`id`, `colName1`, `colName2`, `colName3`) VALUES (820, 'string', 5, 'N') ON DUPLICATE KEY UPDATE `colName1`=VALUES(`colName1`), `colName2`=VALUES(`colName2`), `colName3`=VALUES(`colName3`) -- Tried with and without ` surrounding column names after ON