mysql-python

Django queryset objects return None instead of 0 even though the database has 0 stored as the field value

我只是一个虾纸丫 提交于 2019-12-04 02:06:17
问题 I encountered a problem when I started using mysql-connector/python instead of mysqlclient for my Django project. Suddenly values stored as 0 in the database is turned to "None" in the resulting queryset, here's an example. queryset = Invoices.objects.all().filter(sold=0) print(queryset[0].sold) # Prints "None" Where the same statement would have printed 0 with mysqlclient. Is there a good way to fix this? I haven't gotten mysqlclient to work well with my current setup and would rather not

How to install MySQLdb with python 3.2

人走茶凉 提交于 2019-12-04 01:35:04
问题 I'm trying to connect to mySQL with python. From what I understand you need to have MySQLdb which is some python connector module. My first problem was not having the right version of the mySQLdb. It can be found here. Then I am supposed to open a command line window and navigate to the path of the file I just downloaded (after unzipping) and type python setup.py build This then gave me an error saying that I needed to downloaded setup tools. Setup tools apparently was discontinued after

MySQLdb is extremely slow with large result sets

醉酒当歌 提交于 2019-12-04 01:07:27
问题 I executed the following query both in phpMyAdmin & MySQLdb (python). SELECT *, (SELECT CONCAT(`id`, '|', `name`, '|', `image_code`) FROM `model_artist` WHERE `id` = `artist_id`) as artist_data, FIND_IN_SET("metallica", `searchable_words`) as find_0 FROM `model_song` HAVING find_0 phpMyAdmin said the query took 2ms . My python code said that using MySQLdb the query took 848ms (without even fetching the results). The python code: self.db = MySQLdb.connect(host="localhost", user="root", passwd=

“Can't initialize character set utf8mb4” with Windows mysql-python

百般思念 提交于 2019-12-04 00:32:29
问题 I'm getting an error try to connect to a remote mysql database from a Windows 7 client via python 2.7 + MySQLdb 1.2.5 + sqlalchemy 1.0.9 . This is a result of recently changing the server's default character set to utf8mb4 . The server is running MySQL 5.5.50 . I connect like this: DB_ENGINE = sqlalchemy.create_engine("mysql+mysqldb://{user}:{pass}@{host}:{port}/{database}?charset=utf8mb4".format(**DB_SETTINGS)) Session = sqlalchemy.orm.sessionmaker(bind=DB_ENGINE) The error is: File "C:

python mysql.connector DictCursor?

非 Y 不嫁゛ 提交于 2019-12-03 22:53:54
In Python mysqldb I could declare a cursor as a dictionary cursor like this: cursor = db.cursor(MySQLdb.cursors.DictCursor) This would enable me to reference columns in the cursor loop by name like this: for row in cursor: # Using the cursor as iterator city = row["city"] state = row["state"] Is it possible to create a dictionary cursor using this MySQL connector? http://dev.mysql.com/doc/connector-python/en/connector-python-example-cursor-select.html Their example only returns a tuple. I imagine the creators of MySQL would eventually do this for us? J1MF0X According to this article it is

pip3 install mysql-python failed with error code 1 in /tmp/pip-install-4nev4id4/mysql-python/

瘦欲@ 提交于 2019-12-03 22:46:05
问题 I am new in python on flask, when i try to install mysql-python by entering the following command in terminal pip3 install mysql-python it shows the following error: Collecting mysql-python Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-install-4nev4id4/mysql

Python MySQLdb not importing

核能气质少年 提交于 2019-12-03 21:22:37
I have installed mysql server using $ sudo apt-get install mysql-server then I installed python-mysqldb using $ sudo apt-get install python-mysqldb but when I import MySQLdb in python it shows the following error >>> import MySQLdb Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named MySQLdb I reinstalled both mysql server and python-mysqldb but it shows the same error. What am I getting wrong? lee penkman You needed to install the module with pip pip install mysql-python Python module names are case sensitive, even on case-insensitive file

MySQLdb is caching SELECT results?

雨燕双飞 提交于 2019-12-03 20:52:25
问题 i'm running a SELECT query in a loop. Once in a while, the database table is updated (by another program). The first SELECT retrieves the correct data, but further calls in the loop return the first values . How can I retrieve up-to-date data? The only workaround I found so far, is reconnect to the DB on each iteration! In my example, uncommenting BOTH comment #1# and #2#. Uncommenting only #2# is not enough (i.e., cursor is recreated), the results are still cached. Here's a working sample

Python MySQLdb: Query parameters as a named dictionary [closed]

回眸只為那壹抹淺笑 提交于 2019-12-03 18:03:47
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 11 months ago . I want to pass query parameters to cursor.execute() method of MySQLdb as a named dictionary, such that they are escaped from SQL injection. Can you explain why this gives KeyError : >>> c.execute('select id from users where username=%(user)s', {'user':'bob',}) KeyError: 'user' MySQLdb manual http://mysql

error installing mysql-python and none of mentioned solutions worked

此生再无相见时 提交于 2019-12-03 16:51:29
I just wanted to install Mysql-python, but every time errors occur. I have tried all mentioned solutions as installing wheel, using easy_install, renewing visual c++ for python, installing mysql connector, even installing latest mysql itself,and every other things came to my sight and my mind. I have python 2.7.11 on windows 10. and I have installed most of windows updates. always it occurs: easy_install Mysql-python Searching for Mysql-python Reading https://pypi.python.org/simple/Mysql-python/ Best match: MySQL-python 1.2.5 Downloading https://pypi.python.org/packages/a5/e9