mysql-python

How to update multiple rows with single MySQL query in python?

丶灬走出姿态 提交于 2019-11-28 09:24:55
#!/usr/bin/python # -*- coding: utf-8 -*- import MySQLdb as mdb con = mdb.connect('localhost', 'root', 'root', 'kuis') with con: cur = con.cursor() cur.execute("UPDATE Writers SET Name = %s WHERE Id = %s ", ("new_value" , "3")) print "Number of rows updated:", cur.rowcount With above code the third row's value of the table Writers in the database kuis gets updated with new_value and the output will be Number od rows updated: 1 How am I supposed to update multiple rows at the same time? Probably you are looking for cursor.executemany . cur.executemany("UPDATE Writers SET Name = %s WHERE Id = %s

Django MySQLdb version doesn't match _mysql version Ubuntu

故事扮演 提交于 2019-11-28 07:47:02
问题 I'm trying to get a django site deployed from a repository. I was almost there, and then changed something (I'm not sure what!!) and was back to square one. Now I'm trying to run ./manage.py syncdb and get the following error: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: this is MySQLdb version (1, 2, 3, 'final', 0), but _mysql is version (1, 2, 2, 'final', 0) I've searched forums for hours and none of the solutions presented helped. I tried uninstalling and re

cc1: error: unrecognized command line option “-Wno-null-conversion” within installing python-mysql on mac 10.7.5

耗尽温柔 提交于 2019-11-28 06:04:59
This error broke my python-mysql installation on Mac 10.7.5. Here are the steps The installed python is 2.7.1, mysql is 64 bit for 5.6.11. The being installed python-mysql is 1.2.4, also tried 1.2.3 Configurations for the installation 1) sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql 2) Edit the setup_posix.py and change the following mysql_config.path = "mysql_config" to mysql_config.path = "/usr/local/mysql/bin/mysql_config" 3) sudo python setup.py build Here is the stacktrace for build running build running build_py copying MySQLdb/release.py -> build/lib.macosx-10.7-intel-2.7

Python MySQLdb: connection.close() VS. cursor.close()

僤鯓⒐⒋嵵緔 提交于 2019-11-28 04:39:05
If I use MySQLdb to connect to MySQL-Server through Python. I create a connection and a cursor like this: connection = MySQLdb.connect(...) cursor = connection.cursor() # process When the MySQL-processing is done one should close the connection . Now I was wondering: Is it sufficient to close the connection by doing: connection.close() or do I have to close the cursor first and then the connection ? Like this: cursor.close() connection.close() S.Lott Use with , this tool allows you to create a temporary cursor that will be closed once you return to your previous indentation level. from

django - Error loading MySQLdb module: No module named MySQLdb

非 Y 不嫁゛ 提交于 2019-11-28 04:38:39
问题 I'm using Django 1.4.1 with Active Python 2.7 on Win7. I have installed the MySQL module using pypm install mysql-python . The database engine is django.db.backends.mysql . import MySQLdb works in the interactive shell. .\manage.py syncdb created the tables with no problem. However, when I open the site in the browser, I get Error loading MySQLdb module: No module named MySQLdb : Environment: Request Method: GET Request URL: http://whatever/ Django Version: 1.4.1 Python Version: 2.7.2

What's the difference between MySQLdb, mysqlclient and MySQL connector/Python?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 03:08:21
So I've been trying to do some database update with python and while setting up the whole dev environment, I came across these three things which made me dizzy. There's MySQLdb There's mysqlclient And then there's a mysql connector python What's each of them, the difference and where to use them? Thanks MySQLdb is a thin python wrapper around C module which implements API for MySQL database. There was MySQLDb1 version of wrapper used some time ago and now it is considered to be a legacy. As MySQLDb1 started evolving to MySQLDb2 with bug fixes and Python3 support, a MySQLDb1 was forked and here

Replacing Pandas or Numpy Nan with a None to use with MysqlDB

房东的猫 提交于 2019-11-28 03:03:27
I am trying to write a Pandas dataframe (or can use a numpy array) to a mysql database using MysqlDB . MysqlDB doesn't seem understand 'nan' and my database throws out an error saying nan is not in the field list. I need to find a way to convert the 'nan' into a NoneType. Any ideas? Andy Hayden @bogatron has it right, you can use where , it's worth noting that you can do this natively in pandas: df1 = df.where((pd.notnull(df)), None) Note: this changes the dtype of all columns to object . Example: In [1]: df = pd.DataFrame([1, np.nan]) In [2]: df Out[2]: 0 0 1 1 NaN In [3]: df1 = df.where((pd

mysql-python on mac os 10.9.1

女生的网名这么多〃 提交于 2019-11-28 01:57:02
问题 I can't seem to be able to install mysql-python on 10.9.1. I suspect it has something to do with latest command line tools update but I'm no expert: Running MySQL-python-1.2.5/setup.py -q bdist_egg --dist-dir /var/folders/s7/j138zlt172nf6qqpn98rhzhm0000gn/T/easy_install-kq86vo/MySQL-python-1.2.5/egg-dist-tmp-edndmM clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future] clang: note: this will be a hard error (cannot be downgraded to a warning)

Failed building wheel for mysql-python

江枫思渺然 提交于 2019-11-28 01:09:56
问题 I want to run a Django application in PyCharm which works on MySQL DB. I am unable to connect my program to the database. When I am trying to install MySQLclient or MySQL-python I am getting the error: Failed building wheel for MySQLclient Please help me out in connecting my Django program with MySQL database. 回答1: Edit Please try installing the .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/. This works every time. Just type pip install MySQL_python‑1.2.5‑cp27‑none‑win32.whl in the

Why MYSQL IN keyword not considering NULL values

落花浮王杯 提交于 2019-11-27 23:06:59
I am using the following query: select count(*) from Table1 where CurrentDateTime>'2012-05-28 15:34:02.403504' and Error not in ('Timeout','Connection Error'); Surprisingly, this statement doesnot include the rows having Error value as NULL.My intention is to filter only rows with Error value as 'Timeout' (or) 'Connection Error'. I need to give an additional condition( OR Error is NULL) to retrieve the correct result. Why is MYSQL filtering out results with NULL values? I thought that IN keyword would return a boolean result (1/0) and now i understand that some MYSQL keywords doesnt return