mysql-python

MariaDB / Python issues with emoji characters

帅比萌擦擦* 提交于 2019-12-13 15:53:51
问题 I have a string in x['foo'] , sometimes it's a normal string, other times it is a emoji or text art .. So, I am getting this error in trying to submit the content into database. Warning: Incorrect string value: '\xE4\xB8\xBA Co...' for column 'description' at row 1 If I use x['foo'].decode("utf-8") I get this error: UnicodeEncodeError: 'ascii' codec can't encode character u'\u4e3a' in position 0: ordinal not in range(128) If I try, encode('ascii', 'ignore').decode('ascii') Then I get this

How to divide 2 VARCHAR(255) values and insert into row (MySQL, Python)

流过昼夜 提交于 2019-12-13 04:39:21
问题 Table data: I have a table cpu with the columns name, price, id, mark, value Data format: The price value is $xxx.xx and the mark value is xxxxxx both stored as VARCHAR(255)'s. Question: How can i divide price into mark and then store that variable in value for each row using MySQL python? I had the following idea regarding code: for each row get price and mark check they both have a value, convert price to a float by removing the "$" and setting it to a float. I could then set mark to a

There is an TypeError: execute() takes at most 3 arguments (6 given) when inserting into mysql table

霸气de小男生 提交于 2019-12-13 04:35:42
问题 I have made a webscraper in python and I am now trying to get it to output the data i have scraped into a mysqldb but I keep getting this error and I don't know how to fix it.this is the error I get File "C:/Users/owner/Downloads/Scrape (2).py", line 16, in <module> cursor.execute("INSERT INTO london10dayforecast (Day,Condition,High,Low,) VALUES (?,?,?,?)", str(var1),str(var2),str(var3),str(var4)) TypeError: execute() takes at most 3 arguments (6 given) Process finished with exit code 1 Here

Difficulty connecting Python3 to a MariaDB - take 1

偶尔善良 提交于 2019-12-13 03:58:33
问题 See related question at: Difficulty connecting python3 to a mariadb - take2 I have Python2.7 and python3 installed on an OpenSuse (Leap 15.1) and I have I have MariaDB installed uname -a Linux TRANQUILITY 4.12.14-lp151.28.13-default #1 SMP Wed Aug 7 07:20:16 UTC 2019 (0c09ad2) x86_64 x86_64 x86_64 GNU/Linux python2.7 --version Python 2.7.14 python3 --version Python 3.6.5 mysql --version mysql Ver 15.1 Distrib 10.2.25-MariaDB, for Linux (x86_64) using EditLine wrapper My program is meant to

Improving MySQLdb load data infile performance

ⅰ亾dé卋堺 提交于 2019-12-13 02:49:33
问题 I have a table that's roughly defined as follows in InnoDB: create table `my_table` ( `time` int(10) unsigned not null, `key1` int(10) unsigned not null, `key3` char(3) unsigned not null, `key2` char(2) unsigned not null, `value1` float default null, `value2` float default null, primary key (`key1`, `key2`, `key3`, `time`), key (`key3`, `key2`, `key1`, `time`) ) engine=InnoDB default character set ascii partition by range(time) ( partition start values less than (0), partition from20180101

Python subprocess.call seems to ignore parameters

◇◆丶佛笑我妖孽 提交于 2019-12-13 02:27:26
问题 I have written two small functions in Python to call mysqldump and mysql from console, so I am able to create a database backup and then restore it: # Makes a backup current database status def backupDatabase(): if(os.path.exists('myDatabaseBackup.sql')): os.remove('myDatabaseBackup.sql') call(['mysqldump', '-u myUsername myDatabase > myDatabaseBackup.sql']) # Restores database def restoreDatabase(): call(['mysql', '-u myUsername myDatabase < myDatabaseBackup.sql']) Nevertheless, they are not

Calling DATE_FORMAT() in MySQL from Django fails

隐身守侯 提交于 2019-12-13 01:25:20
问题 I can run SET statements to assign variables and use "transaction" to maintain it in the mySQL session, but when I include the function DATE_FORMAT like this: cursor.execute("SET @dowToday:=CAST( DATE_FORMAT( NOW(), '%w' ) AS UNSIGNED);") Django complains that not enough arguments for format string in /usr/lib/pymodules/python2.6/MySQLdb/cursors.py in execute, line 151 It doesn't help to remove the CAST or to play with or escape the quotes. Thoughts? 回答1: I totally missed the point in my

Error loading MySQLdb module with Django on OS X

对着背影说爱祢 提交于 2019-12-13 01:16:17
问题 I have a very strange situation that I can't figure out what's wrong. I'm working on a Django project and I: Installed MySQL on OS X Added the DATABASES values: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'OPTIONS': { 'read_default_file': '/path/to/my.cnf', }, } } But then Django/Mezzanine tells me that there's an error loading MySQLdb module. So I Googled for some tips around this and tried these methods: pip install mysql-python Reinstalled pip Downloaded ez_setup.py

mysql-python collation issue: how to force unicode datatype?

折月煮酒 提交于 2019-12-12 20:00:43
问题 For certain purposes I had to change field collations from utf8_unicode_ci to utf8_bin in a database. It turned out that the change lead to changes in datatypes that come to python. The question is how to force mysql-python to return unicode objects to python . Here is a sample that shows the problem (explicit charset forces use_unicode=1): >>> con = MySQLdb.connect(..., charset='utf8') >>> c = c.cursor() >>> c.execute('SELECT %s COLLATE utf8_bin', u'м') 1L >>> c.fetchone() ('\xd0\xbc',) >>>

Load data local infile does not work in Ubuntu 12.04 and MySQL

我的未来我决定 提交于 2019-12-12 18:30:32
问题 Using MySQL I cannot import a file using load data local infile. My server is on AWS RDS. This works on Ubuntu 10.04. I installed the client using apt-get install mysql-client . Same error if I use mysqldb or mysql.connector in Python. File "/usr/lib/pymodules/python2.7/mysql/connector/protocol.py", line 479, in cmd_query return self.handle_cmd_result(self.conn.recv()) File "/usr/lib/pymodules/python2.7/mysql/connector/connection.py", line 179, in recv_plain errors.raise_error(buf) File "/usr