mysql-python

ERROR 2006 (HY000) at line 1: MySQL server has gone away

拜拜、爱过 提交于 2019-12-03 16:46:01
问题 ERROR 2006 (HY000) at line 1: MySQL server has gone away I am facing the same problem. I am trying to restore mysqldump file to my machine. The file have size of 2.7 MB. I am getting "ERROR 2006 (HY000) at line 1: MySQL server has gone away" error. I increased size of max_allowed_packet and wait_timeout. But nothing worked. Following are the content of my file (my-medium.ini), please suggest me where I am wrong. My installation have various ini files, and I have modified, my-large, my-medium,

Python MySQLdb iterate through table

只愿长相守 提交于 2019-12-03 16:27:27
问题 I have a MSQL db and I need to iterate through a table and perform an action once a WHERE clause is met. Then once it reaches the end of the table, return to the top and start over. Currently I have cursor = database.cursor() cursor.execute("SELECT user_id FROM round WHERE state == -1 AND state = 2") round_id = cursor.fetchone() if round != 5 ...do stuff in a loop but this obviously only keeps looping the first entry. I guess you need to use the for in function to read through the table, but

CA SSL parameter for Python MySQLdb not working, but key does?

痞子三分冷 提交于 2019-12-03 15:58:23
I'm trying to connect to a MySQL DB that requires SSL (only doing server authentication, not mutual). I have the server's CA saved as a .pem in the same directory I'm running the script from. My connection string looks like this: ssl_settings = {'ca':'ca.pem'} conn = MySQLdb.connect(host=HOST, user=USER, passwd=PASS, db=DB, ssl=ssl_settings} This results in "Error 2026: SSL connection error". However, if I change ssl_settings to: ssl_settings = {'key':'ca.pem'} The database connects just fine and the script executes. From my understanding of the SSL parameters, 'cert' and 'key' should only be

TypeError: 'int' object is not iterable - Python

允我心安 提交于 2019-12-03 15:55:26
I got the following error: File "/home/ec2-user/test/test_stats.py", line 43, in get_test_ids_for_id cursor.execute("""select test_id from test_logs where id = %s """, (id)) File "/home/ec2-user/.etl/lib/python2.7/site-packages/MySQLdb/cursors.py", line 187, in execute query = query % tuple([db.literal(item) for item in args]) TypeError: 'int' object is not iterable Here's the section of my code I'm having trouble with: def get_test_ids_for_id(prod_mysql_conn, id): cursor = prod_mysql_conn.cursor() cursor.execute("""select test_id from test_logs where id = %s """, (id)) rows = cursor.fetchall(

How to check if record exists with Python MySQdb

纵饮孤独 提交于 2019-12-03 13:15:10
Im creating a python program that connects to mysql. i need to check if a table contains the number 1 to show that it has connected successfully, this is my code thus far: xcnx.execute('CREATE TABLE settings(status INT(1) NOT NULL)') xcnx.execute('INSERT INTO settings(status) VALUES(1)') cnx.commit() sqlq = "SELECT * FROM settings WHERE status = '1'" xcnx.execute(sqlq) results = xcnx.fetchall() if results =='1': print 'yep its connected' else: print 'nope not connected' what have i missed? i am an sql noob, thanks guys. I believe the most efficient "does it exist" query is just to do a count :

Is __enter__ and __exit__ behaviour for connection objects specified in the Python database API?

六月ゝ 毕业季﹏ 提交于 2019-12-03 13:04:31
Background I recently discovered the Python with keyword and started seeing its potential usefulness for more prettily handling some scenarios where I'd previously have used try: ... finally: ... constructs. I immediately decided to try it out on the MySQLdb connection object in some code I was writing. I didn't bother reading up on how __enter__ and __exit__ behave in implementors of the Python database API, and naively expected the behaviour to be like that of file objects - all I was expecting was for exit to call connection.close() . Imagine my confusion, then, at this behaviour: >>> with

Have MySQLdb installed, works outside of virtualenv but inside it doesn't exist. How to resolve?

◇◆丶佛笑我妖孽 提交于 2019-12-03 12:28:38
I'm using the most recent versions of all software (Django, Python, virtualenv, MySQLdb) and I can't get this to work. When I run "import MySQLdb" in the python prompt from outside of the virtualenv, it works, inside it says "ImportError: No module named MySQLdb". I'm trying to learn Python and Linux web development. I know that it's easiest to use SQLLite, but I want to learn how to develop larger-scale applications comparable to what I can do in .NET. I've read every blog post on Google and every post here on StackOverflow and they all suggest that I run "sudo pip install mysql-python" but

Correct exception handling with python MySQLdb connection

感情迁移 提交于 2019-12-03 12:17:22
I created a small/basic python script to insert data into a MySQL database. I included some error handling - mainly to close the connection and/or prevent hanging connections in the case of an error (...but also to ignore some errors). I thought what I had (see below) was right - it seemed to be working okay. But occasionally I have been getting "Too many connection" errors - which I assumes means I am not actually closing the connection correctly at all (or perhaps error handling isn't right). conn=MySQLdb.connect(host=####, user=####, passwd=####, db=####) curs=conn.cursor() try: curs

Using PIP in a virtual environment, how do I install MySQL-python

夙愿已清 提交于 2019-12-03 11:29:04
问题 When I'm in my virtual environment, I attempt to run: pip install MySQL-python This didn't work, so I tried downloading the package and installing it by running: python setup.py install This returns the following error: % python setup.py install ~VIRTUAL_ENV/build/MySQL-python running install install_dir /home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/ running bdist_egg running egg_info writing MySQL_python.egg-info/PKG-INFO writing top-level names to MySQL

Why doesn't the MySQLdb Connection context manager close the cursor?

两盒软妹~` 提交于 2019-12-03 09:57:22
MySQLdb Connections have a rudimentary context manager that creates a cursor on enter , either rolls back or commits on exit , and implicitly doesn't suppress exceptions. From the Connection source : def __enter__(self): if self.get_autocommit(): self.query("BEGIN") return self.cursor() def __exit__(self, exc, value, tb): if exc: self.rollback() else: self.commit() So, does anyone know why the cursor isn't closed on exit? At first, I assumed it was because closing the cursor didn't do anything and that cursors only had a close method in deference to the Python DB API (see the comments to this