mysql-python

Python MySQLdb WHERE SQL LIKE

你。 提交于 2019-12-18 03:44:45
问题 I have recently started to learn Python and MySQL for web purposes and I have run into a following problem : I want to pull out from a mysql database one record that contains any text that I enter in param section, howerver I am running into following problem when making a query: traceback (most recent call last): File "/Users/Strielok/Desktop/test.py", line 13, in <module> c.execute("SELECT * FROM data WHERE params LIKE ('%s%') LIMIT 1" % (param)) TypeError: not enough arguments for format

how to insert to a mysql table using mysaldb, where the table name is in a python variable?

帅比萌擦擦* 提交于 2019-12-18 03:43:57
问题 I'm using python-mysql db api to insert some values to a table where the table name is in a python variable. So I wrote the below code DB_CURSOR.execute("""INSERT INTO %s (name,created_by,state,description,docs,admin_email,date_created) VALUES(%s,%s,%s,%s,%s,%s,%s)""", (hosts_table, hostname, created_by, state, description, docroot, admin_email, date_created)) As you see the table name is in the hosts_table variable. The problem is mysqldb quotes the table name and i get a mysql error. It

MySQLClient instal error: “raise Exception(”Wrong MySQL configuration: maybe https://bugs.mysql.com/bug.php?id"

ぃ、小莉子 提交于 2019-12-17 22:43:40
问题 I am trying to install mysqlclient to my Python 3.6. Originally what i want to install is MySQLdb, however it was saying that MySQLdb does not work with Python 3 (still?). So i switch to mysqlclient. pip3 install mysqlclient However, it was given this error: Collecting mysqlclient Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz Complete output from command python setup.py egg_info: Traceback

“my_config.h” file not found when install mysql-python on osx 10.8

南笙酒味 提交于 2019-12-17 21:42:34
问题 I face this problem when I want to install mysql-python on osx 10.8, it show error with 'my_config.h' file not found. Below is my running code: sudo easy_install mysql-python Password: Searching for mysql-python Reading http://pypi.python.org/simple/mysql-python/ Reading http://sourceforge.net/projects/mysql-python/ Reading http://sourceforge.net/projects/mysql-python Best match: MySQL-python 1.2.3 Downloading http://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.3.tar.gz#md5

Python can find a module…and then it can't

坚强是说给别人听的谎言 提交于 2019-12-17 21:36:35
问题 I am finally going full steam into Python, but for some reason I have an issue where Python can find a module in the interactive CLI and then it can't when I write a script. The module is specifically mysql.connector located in /Library/Python/2.7/site-packages . As you can see from the interactive CLI session, it imports mysql.connector just fine. Echoing the sys.path shows 'Library/Python/2.7/site-packages' Here's a new CLI window (I'm on a Mac 10.10). Note: initially when I login I am

Why isn't the 'insert' function adding rows using MySQLdb?

旧时模样 提交于 2019-12-17 21:29:56
问题 I'm trying to figure out how to use the MySQLdb library in Python (I am novice at best for both of them). I'm following the code here, specifically: cursor = conn.cursor () cursor.execute ("DROP TABLE IF EXISTS animal") cursor.execute (""" CREATE TABLE animal ( name CHAR(40), category CHAR(40) ) """) cursor.execute (""" INSERT INTO animal (name, category) VALUES ('snake', 'reptile'), ('frog', 'amphibian'), ('tuna', 'fish'), ('racoon', 'mammal') """) print "Number of rows inserted: %d" %

MySQLdb returns not all arguments converted with “on duplicate key update”

家住魔仙堡 提交于 2019-12-17 19:06:11
问题 With MySQLdb package in python, I want to insert records with checking some unique keys. The method I used is executemany. The arguments are sql sentence and a tuple. But when I executed it, it raised an error which said "not all argument converted". The codes are as following: dData = [[u'Daniel', u'00-50-56-C0-00-12', u'Daniel']] sql = "INSERT INTO app_network_white_black_list (biz_id, shop_id, type, mac_phone, remarks, create_time) " \ "VALUES ({bsid}, {shop_id}, {type}, %s, %s, NOW()) " \

Installing MySQL-python on mac

China☆狼群 提交于 2019-12-17 15:28:17
问题 I am using OSX 10.8 and PyCharm to work on a Python development project. I have installed MySQL-python for the mac using the instructions on the website http://blog.infoentropy.com/MySQL-python_EnvironmentError_mysql_config_not_found However, running the project gives me this error: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/ashishagarwal/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so, 2): Symbol not found: _mysql

Installing MySQL-python on mac

别等时光非礼了梦想. 提交于 2019-12-17 15:26:01
问题 I am using OSX 10.8 and PyCharm to work on a Python development project. I have installed MySQL-python for the mac using the instructions on the website http://blog.infoentropy.com/MySQL-python_EnvironmentError_mysql_config_not_found However, running the project gives me this error: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/ashishagarwal/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so, 2): Symbol not found: _mysql

Python MySQLdb returns datetime.date and decimal

血红的双手。 提交于 2019-12-17 10:51:09
问题 I have a MySQL query like: SELECT mydate, countryCode, qtySold from sales order mydate, countryCode This returns tuples of tuples with values like: ((datetime.date(2011, 1, 3), 'PR', Decimal('1')), (datetime.date(2011, 1, 31), 'MX', Decimal('1'))) When I try printing this using a loop, it prints perfectly fine: 2011-1-3, PR, 1 2011-1-31, MX, 1 But when I try to return this value, it returns as datetime.date(2011, 1, 3), 'PR', Decimal('1') Is there a way that I can get normal data so that I