python mysql.connector DictCursor?

According to this article it is available by passing in ‘dictionary=True’ to the cursor constructor: http://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursordict.html so I tried: cnx = mysql.connector.connect(database=”bananas”) cursor = cnx.cursor(dictionary=True) and got: TypeError: cursor() got an unexpected keyword argument ‘dictionary’ and I tried: cnx = mysql.connector.connect(database=”bananas”) cursor = cnx.cursor(named_tuple=True) and got: TypeError: cursor() got an unexpected keyword argument ‘named_tuple’ and … Read more

How can I use executemany to insert into MySQL a list of dictionaries in Python

itemBank = [] for row in rows: itemBank.append(( tempRow2[‘Item_Name’], tempRow1[‘Item_Price’], tempRow3[‘Item_In_Stock’], tempRow4[‘Item_Max’], getTimeExtra )) #append data q = “”” insert ignore into TABLE1 ( Item_Name, Item_Price, Item_In_Stock, Item_Max, Observation_Date ) values (%s,%s,%s,%s,%s) “”” try: x.executemany(q, itemBank) conn.commit() except: conn.rollback() Hope it will help you

How to retrieve table names in a mysql database with Python and MySQLdb?

To be a bit more complete: import MySQLdb connection = MySQLdb.connect( host=”localhost”, user=”myself”, passwd = ‘mysecret’) # create the connection cursor = connection.cursor() # get the cursor cursor.execute(“USE mydatabase”) # select the database cursor.execute(“SHOW TABLES”) # execute ‘SHOW TABLES’ (but data is not returned) now there are two options: tables = cursor.fetchall() # return data … Read more

Suggested way to run multiple sql statements in python?

I would create a stored procedure: DROP PROCEDURE IF EXISTS CopyTable; DELIMITER $$ CREATE PROCEDURE CopyTable(IN _mytable VARCHAR(64), _table_name VARCHAR(64)) BEGIN SET FOREIGN_KEY_CHECKS=0; SET @stmt = CONCAT(‘DROP TABLE IF EXISTS ‘,_table_name); PREPARE stmt1 FROM @stmt; EXECUTE stmt1; SET FOREIGN_KEY_CHECKS=1; SET @stmt = CONCAT(‘CREATE TABLE ‘,_table_name,’ as select * from ‘, _mytable); PREPARE stmt1 FROM @stmt; … Read more

“cannot find -lssl; cannot find -lcrypto” when installing mysql-python?

You need to have installed the development libraries of OpenSSL. It can be a libssl-dev, libssl-devel if your distribution provides separated packages for the dev libraries. Or install the complete openssl package if they don’t. (venv)➜ src pip install mysql-python==1.2.5 Downloading/unpacking mysql-python==1.2.5 Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded Running setup.py (path:/home/braiam/src/venv/build/mysql-python/setup.py) egg_info for package mysql-python Installing … Read more