Mysql

Mysql Reminder : csv export

logo_mysql_sun_a

I was asked to export some data in a csv format from a Mysql database. I’m just putting it here as a reminder… Thank you so much my blog to extend my brain capacity so much !

SELECT * INTO OUTFILE '/tmp/result.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM dc_account_key WHERE created_at > '2009-01-09' AND active = 0;

I won’t explain this, it’s really straitforward. This is just a reminder, after all.

Building MacPorts Py-Mysql on Leopard

If you installed over your old Tiger or if you are new user, you may have experienced errors when trying to build py-mysql.Py-mysql is a Python module to connect to Mysql.I’m using it to have Django, the Python Web Framework, to connect to Mysql database. This is what I got when trying to install :  

# port install py-mysql
--->  Building py-mysql with target build
Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py-mysql/work/MySQL-python-1.2.2" && /opt/local/bin/python2.4 setup.py build " returned error 1
Command output: running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.3-ppc-2.4/MySQLdb
running build_ext
building '_mysql' extension
/usr/bin/gcc-4.0 -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -fno-common -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/opt/local/include/mysql5/mysql -I/opt/local/Library/Frameworks/Python.framework/Versions/2.4/include/python2.4 -c _mysql.c -o build/temp.macosx-10.3-ppc-2.4/_mysql.o
In file included from /opt/local/include/mysql5/mysql/mysql.h:47,
                 from _mysql.c:40:
/usr/include/sys/types.h:92: error: duplicate 'unsigned'
/usr/include/sys/types.h:92: error: two or more data types in declaration specifiers
error: command '/usr/bin/gcc-4.0' failed with exit status 1

Error: Status 1 encountered during processing.

I tried to upgrade MacPorts… but I already had the latest.

# port selfupdate

MacPorts base version 1.600 installed

Downloaded MacPorts base version 1.600

The MacPorts installation is not outdated and so was not updated
selfupdate done!

I finaly found the solution on http://rob.cogit8.org/blog/2007/Nov/14/installing-django-leopard-mac-os-105/