mysql-python

Connect to Database via proxy a python script

人走茶凉 提交于 2019-12-23 08:08:13
问题 I have a python script that connects to a remote MySQL database using the python library MySQLdb. It works fine but how can I get it to connect through a proxy that I'm behind when at work. I can connect via the command line in ssh, but how do I get the python script to use the proxy settings. There doesnt seem to be any options in the MySQLdb commands for proxy configurations. import MySQLdb as mdb conn=mdb.connect(host='mysite.com',user='myuser',passwd='mypassword',db='mydb') cursor = conn

Connect to Database via proxy a python script

两盒软妹~` 提交于 2019-12-23 08:08:06
问题 I have a python script that connects to a remote MySQL database using the python library MySQLdb. It works fine but how can I get it to connect through a proxy that I'm behind when at work. I can connect via the command line in ssh, but how do I get the python script to use the proxy settings. There doesnt seem to be any options in the MySQLdb commands for proxy configurations. import MySQLdb as mdb conn=mdb.connect(host='mysite.com',user='myuser',passwd='mypassword',db='mydb') cursor = conn

Global query timeout in MySQL 5.6

和自甴很熟 提交于 2019-12-23 07:46:10
问题 I need to apply a query timeout at a global level in my application. The query: SET SESSION max_execution_time=1 does this with MySQL 5.7. I am using MySQL 5.6 and cannot upgrade at the moment. Any solution with SQL Alchemy would also help. 回答1: It seems there is no equivalent to max_execution_time in MySQL prior to versions 5.7.4 and 5.7.8 (the setting changed its name). What you can do is create your own periodic job that checks if queries have exceeded timeout and manually kill them.

creating Tables and columns dynamically using mysql python connector

家住魔仙堡 提交于 2019-12-23 05:42:10
问题 I want to create a table having columns dynamically using python list. Column Names are in the list and I want to refer them in the MySQL query. I am using MySQL.connector with python 3.4.3. Below is the code which I tried: col names: ['Last Name', 'First Name', 'Job', 'Country'] table_name = 'stud_data' query = "CREATE TABLE IF NOT EXISTS"+table_name+"("+"VARCHAR(250),".join (col) + "Varchar(250))" print("Query is:" ,query) cursor.execute(query) conn.commit() But I am getting the following

Unable to install mysql client 1.3.12 getting fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory

这一生的挚爱 提交于 2019-12-23 04:59:16
问题 I am trying to install mysqlclient==1.3.12 from python 3.7.3 using pip install command and I am facing below error: _mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.20.27508\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2 And below is the log: Building wheels for collected packages: mysqlclient Building wheel for mysqlclient (setup.py) ..

Python MySQLdb error - what is causing this

China☆狼群 提交于 2019-12-23 03:57:07
问题 I am wondering why I am receiving this error: cmd = "INSERT INTO resulttest (category, value, timestamp) VALUES (" + key + ", " + str(value) + ", " + str(timestamp) + ")" c.execute(cmd) db.commit() INSERT INTO resulttest (category, value, timestamp) VALUES (composed, 2, 1343186948.8) Traceback (most recent call last): File "C:/Behavioral Technology/Google Drive/twitterthingv5test.py", line 94, in <module> moodParser() File "C:/Behavioral Technology/Google Drive/twitterthingv5test.py", line 92

MySQLdb.cursors.Cursor.execute returns different values in case of different cursors why?

梦想的初衷 提交于 2019-12-22 18:20:33
问题 See these two python code snippets, conn = MySQLdb.connect(c['host'], c['user'], c['password'], c['db']) cur = conn.cursor() cur.execute("select * from geo_weathers;) -> **1147L** and conn = MySQLdb.connect(c['host'], c['user'], c['password'], c['db'], cursorclass=MySQLdb.cursors.SSCursor) cur = conn.cursor() cur.execute("select * from geo_weathers") -> **18446744073709551615L** Why the returned number of rows are different in above two cases ? And just FYI there are 1147 rows in a table.

1064, “You have an error in your SQL syntax;…” Python MySQL

…衆ロ難τιáo~ 提交于 2019-12-22 11:25:07
问题 So I have been working on this since last Friday and cannot get around this error: 1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[u'161010-035670'] WHERE order_id=87' at line 1" or something along the same lines as this error. Basically my python will grab data from MySQL database, it creates a case in SalesForce using Simple-Salesforce and then queries that case it created correctly but I need it

MySQL and lock a table, read, and then truncate

倾然丶 夕夏残阳落幕 提交于 2019-12-22 08:44:24
问题 I am using mysqldb in python. I need to do the following for a table. 1) Lock 2) Read 3) Truncate the table 4) Unlock When I run the below code, I get the below error. So, I am rather unsure on how to lock a table for reading it, then truncating the table. I need to be sure that no other connection reads the data. asin_list = [] conn = MySQLdb.connect(host=parms['database']['operations']['host'],user=parms['database']['operations']['username'],passwd=parms['database']['operations']['password'

python easy_install: specify directory housing required files

只愿长相守 提交于 2019-12-22 08:10:13
问题 I'm trying to use easy_install to install MySQL-python. It fails almost immediately: _mysql.c:36:23: error: my_config.h: No such file or directory _mysql.c:38:19: error: mysql.h: No such file or directory _mysql.c:39:26: error: mysqld_error.h: No such file or directory _mysql.c:40:20: error: errmsg.h: No such file or directory It can't find the headers. I have the headers installed, they're just installed from source in /opt. It's obviously not looking there. How do I make it look there? For