mysql-python

About MySQLdb conn.autocommit(True)

一笑奈何 提交于 2020-01-19 12:48:22
问题 I have installed python 2.7 64bit,MySQL-python-1.2.3.win-amd64-py2.7.exe. I use the following code to insert data : class postcon: def POST(self): conn=MySQLdb.connect(host="localhost",user="root",passwd="mysql",db="dang",charset="utf8") cursor = conn.cursor() n = cursor.execute("insert into d_message (mid,title,content,image) values(2,'xx','ccc','fff')") cursor.close() conn.close() if n: raise web.seeother('/') This results in printing n as 1, but in mysql client data aren't visible. google

About MySQLdb conn.autocommit(True)

白昼怎懂夜的黑 提交于 2020-01-19 12:48:18
问题 I have installed python 2.7 64bit,MySQL-python-1.2.3.win-amd64-py2.7.exe. I use the following code to insert data : class postcon: def POST(self): conn=MySQLdb.connect(host="localhost",user="root",passwd="mysql",db="dang",charset="utf8") cursor = conn.cursor() n = cursor.execute("insert into d_message (mid,title,content,image) values(2,'xx','ccc','fff')") cursor.close() conn.close() if n: raise web.seeother('/') This results in printing n as 1, but in mysql client data aren't visible. google

python mysql error in query

六眼飞鱼酱① 提交于 2020-01-17 14:01:50
问题 I want to generate a dynamic table: columnames=[element[0] for element in bufferdata['data'] ] for index,element in enumerate(columnames): columnames[index]=re.sub("[(%./)-]","",element) tuple(columnames) querycreatetable='''CREATE TABLE test (ID INT AUTO_INCREMENT,name VARCHAR(50),symbol VARCHAR(10),sector VARCHAR(50), %s FLOAT,%s FLOAT,%s FLOAT,%s FLOAT,%s FLOAT, %s FLOAT,%s FLOAT,%s FLOAT,%s FLOAT,%s FLOAT, %s FLOAT,%s FLOAT,%s FLOAT,%s FLOAT,%s FLOAT, %s FLOAT,%s FLOAT,%s FLOAT,%s FLOAT,

MySQLdb python insert row or increment count on column if exists

允我心安 提交于 2020-01-15 03:29:44
问题 I have a simple table in MySQL which looks like this: > ID | username | count What I want to achieve using python is: Add username to table, if does not exist, and set count to 1. Whenever the username exists, increment count by 1. What is the best approach for this using MySQLdb in python 2.7 Of course I could do this by querying for username, then if exists update count, but maybe there is a better way of doing this. Thanks ! 回答1: Here is an approach using the link that @johnthexii provided

Python MySQLdb “error: Microsoft Visual C++ 14.0 is required” even though it has been installed

吃可爱长大的小学妹 提交于 2020-01-14 10:46:05
问题 I'm attempting to connect to a MySql database and use its data for some code, though when I'm using pip install mysqlclient it gives me an error stating: "error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools" This link provided does not work, though i found out the correct link and installed the build tools as well as the "Windows 10 SDK" as other posts have specified. I sadly still am getting

Installing MySQLdb for Django on Mac OS X 10.6 Snow Leopard with MAMP

♀尐吖头ヾ 提交于 2020-01-13 03:49:28
问题 So I know this is not a new topic, but its one that nobody has seemed to be able to solve, at least not for Python 2.6 / Snow Leopard. (The Leopard fixes I've found aren't applicable to Snow Leopard.) Situation: I'm trying to get Django installed locally on my Mac OS X Snow Leopard laptop. (10.6.7) I have Python 2.6.1, which is what came preinstalled with Snow Leopard, MySQL-python 1.2.3, and MAMP 1.9.6. All are latest current versions. Without making any changes to the MySQLdb package, if I

Update database with multiple SQL Statments

耗尽温柔 提交于 2020-01-12 03:27:10
问题 I am using mysql connector.Python 1.0.9 downloaded from MySQL site. I have a sample table here DROP TABLE IF EXISTS my_table; CREATE TABLE my_table (id INT NOT NULL AUTO_INCREMENT UNIQUE, Shot VARCHAR(4), sec varchar(5), lay VARCHAR(15) NOT NULL, lay_status VARCHAR(15) NOT NULL, blk VARCHAR(10) NOT NULL, blk_status VARCHAR(15) NOT NULL, pri VARCHAR(10) NOT NULL, pri_status VARCHAR(15) NOT NULL, ani VARCHAR(10) NOT NULL, ani_status VARCHAR(15) NOT NULL, status VARCHAR(5) ); INSERT INTO my

Trouble Setting Up MySQLdb Module

走远了吗. 提交于 2020-01-10 11:45:56
问题 I'm pulling my hair out over here trying to set up MySQLdb on my Mac in order to connect to a remote MySQL server. I have installed the latest C MySQL client libraries I have installed XCode 4 I did naively try to install the module before installing XCode or the client libraries I am attempting to set up the module by running the following commands in terminal: $ sudo python setup.py build $ sudo python setup.py install Both of these commands fail with similar error messages. Here is the

ModuleNotFoundError: No module named 'MySQLdb'

懵懂的女人 提交于 2020-01-10 04:29:05
问题 After finishing of one of my Flask projects, I uploaded it on github just like everybody else. after a 2-3 months period I downloaded the entire githube repository on another machine to run it. However, the app is not working because the packages are not found giving the following message ModuleNotFoundError: No module named 'Flask' So I ended up downloading all packages starting from Flask, SQLalchemy,..etc! but I got stuck with MySQLdb : (MYAPPENV) C:\Users\hp\myapp>python run.py Traceback

How do I check if an insert was successful with MySQLdb in Python?

孤街浪徒 提交于 2020-01-10 01:06:16
问题 I have this code: cursor = conn.cursor() cursor.execute(("insert into new_files (videos_id, filename, " "is_processing) values (%s,%s,1)"), (id, filename)) logging.warn("%d", cursor.rowcount) if (cursor.rowcount == 1): logging.info("inserted values %d, %s", id, filename) else: logging.warn("failed to insert values %d, %s", id, filename) cursor.close() Fun as it is, cursor.rowcount is always one, even though i updated my database to make the videos_id a unique key. That is, the insert fails