mysql-python

ssh first with mysqldb in python

青春壹個敷衍的年華 提交于 2019-11-30 07:15:00
问题 I'm trying to connect to a MySQL database on a remote server using MySQLdb in python. The problem is that first I need to SSH into the host, and then from there, I need to connect to the MySQL server. The problem I'm having, though, is that MySQLdb does not seem to have a way of establishing an SSH connection before connecting to the SQL server. I've checked the documentation but have not had any luck. This is how I'm connecting: conn = MySQLdb.connect(host = 'mysqlhost.domain.com:3306', user

questions about pandas.to_sql

谁都会走 提交于 2019-11-30 05:05:56
I have a question about how to save a dataframe to my local mysql. import MySQLdb import pandas as pd conn=MySQLdb.connect(host="localhost",user='root',passwd="matt123",db="ada") df=pd.DataFrame(['A','B'],columns=['new_tablecol']) df.to_sql(name='new_table',con=conn,if_exists='append') after typing this code , it says pandas.io.sql.DatabaseError: Execution failed on sql 'SELECT name FROM sqlite_master WHERE type='table' AND name=?;': not all arguments converted during string formatting I am confused about this.I can query and create table . but I can't save this dataframe. Your way is not

/usr/bin/ld: cannot find -lpython2.7

最后都变了- 提交于 2019-11-30 03:38:58
I'm trying to install MySQLdb with Python 2.7. The error I'm getting looks like this: gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/opt/python2.7/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 gcc -pthread -shared build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64/mysql -L. -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lmygcc -lpython2.7 -o

GCC-4.2 error on Mac OSX Mountain Lion, unable to install mysql-python

回眸只為那壹抹淺笑 提交于 2019-11-30 00:51:32
I'm having trouble building MySQLdb on Mac OSX Mountain Lion. After upgrading to OSX Mountain Lion from OSX Lion, I have downloaded and installed Xcode 4.4 also. Then, I went to Preference > Downloads of the Xcode and installed Command Line Tools. I've downloaded MySQL-python ver. 1.2.3 from http://sourceforge.net/projects/mysql-python/ When I run python setup.py build I get below message: running build running build_py copying MySQLdb/release.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb running build_ext building '_mysql' extension gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -O2

Python: ValueError: unsupported format character ''' (0x27) at index 1

十年热恋 提交于 2019-11-29 22:21:36
I'm trying to execute a query to search 3 tables in a database using MySQL through Python. Every time I try and execute the following string as a query, it gives me an error about concatenation in the string. "SELECT fileid FROM files WHERE description LIKE '%" + search + "%' OR filename LIKE '%" + search + "%' OR uploader LIKE '%" + search + "%' ORDER BY fileid DESC" This is the error it gives me: ValueError: unsupported format character ''' (0x27) at index 1 If I remove the character it asks for then I have to also remove the %, which stops the query from actually working properly. What can

ImportError: No module named MySQLdb

谁都会走 提交于 2019-11-29 18:54:39
I am referring the following tutorial to make a login page for my web application. http://code.tutsplus.com/tutorials/intro-to-flask-signing-in-and-out--net-29982 I am having issue with the database. I am getting an ImportError: No module named MySQLdb when I execute http://127.0.0.1:5000/testdb I have tried all possible ways to install python mysql, the one mentioned in the tutorial, easy_install, sudo apt-get install. I have installed mysql in my virtual env. My directory structure is just the same as whats explained in the tutorial. The module is sucessfully installed in my system and still

Using a Python variable in MySQL query

别说谁变了你拦得住时间么 提交于 2019-11-29 17:05:51
I am trying to write a function that takes the variable written in the function placeholder() written below and then uses that in MySQL queries. I have written up an example below: import MySQLdb connection = MySQLdb.connect(host = "localhost", user = "root", passwd = "", db = "cars") cursor = connection.cursor() def placeholder(placeholder_variable): sql = "TRUNCATE TABLE %s" cursor.execute(sql, placeholder_variable) placeholder('car_brands') When I try to run this program I get the following error: ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that

pip raises stdio.h not found error on Mac OS X Mavericks (10.9)

跟風遠走 提交于 2019-11-29 14:52:00
问题 I have tried countless solutions at this point and nothing seems to work. I'm trying to install mysql-python, but this happens with numpy and other packages requiring gcc as well: building '_mysql' extension gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -g -O2 -DNDEBUG -g -O3 -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/mysql/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp

Django MySQLdb version doesn't match _mysql version Ubuntu

南笙酒味 提交于 2019-11-29 14:12:06
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-installing MySQL-python and upgrading it. I get the same error when trying to import it from the python

python: MYSQLdb. how to get columns name without executing select * in a big table?

喜欢而已 提交于 2019-11-29 13:46:57
问题 I want to get the column names of a table, but there a over million data in it. So I cannot use: cursor.execute("SELECT * FROM table_name") print cursor.description And in sqlite3, I do it this way crs.execute("PRAGMA table_info(%s)" %(tablename[0])) for info in crs: print info But this is not working in python mysqldb. Any one know how to do that? 回答1: You can use SHOW columns: cursor.execute("SHOW columns FROM table_name") print [column[0] for column in cursor.fetchall()] FYI, this is