If you are in Mac OS X Mavericks and while trying to install MySQL-Python you run into this error:
This is a what makes the trick:
Then, pip works its way towards installing MySQL-Python OK:
Voilà!
Colección de recortes y cosas útiles, simpáticas, interesantes(o las 3!) de Matías Herranz.
Mostrando entradas con la etiqueta mysql. Mostrar todas las entradas
Mostrando entradas con la etiqueta mysql. Mostrar todas las entradas
7 de abril de 2014
5 de julio de 2011
How to install MySQL Server and Python connector in Mac OS X Snow Leopard
================================================================
-> MySQL Server and Python connector(Mac OS X Snow Leopard):
================================================================
Here goes some tricky stuff. You may want to consider getting yourself a cup of
linden infusion :-P
--> If you have a previous MySQL version:
If you have a previous MySQL version, perhaps a 32 bit one, you may encounter several
problems to perform the upgrade to a newer, 64-bit version. But don't worry, the
following steps should get you going in no time.
Hands on!
To uninstall the previous version, do this *in order*:
- First you need to go to: /Library/Receipts and look for a file named
'InstallHistory.plist' (It's just a regular property list)
- Open it and look for the entries regarding MySQL, and delete them.
MacBookPro:~ matias$ cd /Library/Receipts/
MacBookPro:Receipts matias$ sudo nano InstallHistory.plist
ctrl+shift+w, look for the entries regarding MySQL and delete them.
ctrl+o (save) ctrl+x (exit)
- As the installer receipts are actually located in a different place on Snow Leopard:
MacBookPro:Receipts matias$ cd /private/var/db/receipts/
MacBookPro:receipts matias$ ls *mysql*
com.mysql.mysql.bom com.mysql.mysqlstartup.bom
com.mysql.mysql.plist com.mysql.mysqlstartup.plist
MacBookPro:receipts matias$ sudo rm *mysql*
- Now we are ready to do the uninstall work per se, by doing these *in order*:
* Use mysqldump or MySQL Admin to backup your databases to text files!
* Stop the database server
* sudo rm /usr/local/mysql
* sudo rm -rf /usr/local/mysql*
* sudo rm -rf /Library/StartupItems/MySQLCOM
* sudo rm -rf /Library/PreferencePanes/My*
* edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
* rm -rf ~/Library/PreferencePanes/My*
* sudo rm -rf /Library/Receipts/mysql*
* sudo rm -rf /Library/Receipts/MySQL*
* sudo rm /etc/my.cnf
--> Install MySQL (server, startup item, pref pane):
- Install mysql's x86_64 version from the .dmg file. Download the .dmg from
here: http://dev.mysql.com/downloads/mysql/5.1.html#downloads
(I also put the installers under '3rdparty/MacOSX_Installers' folder).
--> Install MySQLdb in the virtualenv
- Turn the virtualenv on. This command does the trick:
MacBookPro:~ matias$ laexpo_start
(Env)MacBookPro:~ matias$
- Fetch MySQL-python-1.2.3 from here: http://sourceforge.net/projects/mysql-python/.
I'll assume you downloaded the .tar.gz file to the Desktop.
- Unpack the tarball, enter the folder:
(Env)MacBookPro:~ matias$ tar xzf MySQL-python-1.2.3.tar.gz
(Env)MacBookPro:~ matias$ cd MySQL-python-1.2.3
- Open the 'site.cfg' file and edit the 'mysql_config' to poin to the path where
you mysql_config resides. For me it is '/usr/local/mysql-5.1.50-osx10.6-x86_64/bin/mysql_config'
- Open the 'setup_posix.py' file and set the 'mysql_config.path' to the same path
you did in the previous step(line 26). Should end up looking like this:
mysql_config.path = "/usr/local/mysql-5.1.50-osx10.6-x86_64/bin/mysql_config"
- Compile the thing:
(Env)MacBookPro:~ matias$ cd ~/Desktop/MySQL-python-1.2.3
(Env)MacBookPro:MySQL-python-1.2.3 matias$ python setup.py clean
(Env)MacBookPro:~ matias$ ARCHFLAGS='-arch x86_64' /usr/bin/python setup.py build
(Env)MacBookPro:~ matias$ ARCHFLAGS='-arch x86_64' python setup.py install
* NOTE 1: It is critical to have the virtualenv activated before running the above
listed command. If it is not, the installation of MySQLdb will be done in
the system and no in the virtualenv and therefore MySQLdb will not be
available when you turn the virtualenv on.
* NOTE 2: It is also critical to set the compilation flags correctly. If not set
correctly, the compilation will default to 32-bit architecture and will
not work afterwards with MySQL.
* NOTE 3: DON'T USE 'sudo' FOR THE COMPILLATION/INSTALL COMMANDS. If you do so, you'll
be installing MySQLdb to the system and not to the virtualenv.
- Confirm the process worked ok:
(Env)MacBookPro:MySQL-python-1.2.3 matias$ python
Python 2.6.1 (r261:67515, Dec 17 2009, 00:59:15)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> MySQLdb.version_info
(1, 2, 3, 'final', 0)
3 de febrero de 2011
Backup/Restore a MySQL dump from the console
Given that tools like MySQL Administrator or MySQL Query Browser most usually won't behave very good when it comes to recovering large db backups, moreover if there is UTF-8 stuff in the dump, I decided to go for the mysql shell, which does much better.
Here some useful commands to have handy:
Dump ALL MySQL Databases
Dump Individual or Multiple MySQL Databases
Dump some particular tables from a MySQL Database
If you want to make sure of not having backwards compatibility issues from the MySQL Server versions between your development and production environments, you may want to add this to the commands:
Reloading the full contents of a database:
Here some useful commands to have handy:
Dump ALL MySQL Databases
mysqldump --user=XXXXXXXX --password=XXXXXXX -A > PATH_TO_SQL_DUMP_FILE.SQL
Dump Individual or Multiple MySQL Databases
mysqldump --user=XXXXXXXX --password=XXXXXXX --databases DB_NAME1 DB_NAME2 DB_NAME3 > PATH_TO_SQL_DUMP_FILE.SQL
Dump some particular tables from a MySQL Database
mysqldump --user=XXXXXXXX --password=XXXXXXXX --databases DB_NAME --tables TABLE_NAME > PATH_TO_SQL_DUMP_FILE.SQL
If you want to make sure of not having backwards compatibility issues from the MySQL Server versions between your development and production environments, you may want to add this to the commands:
--compatible=mysql323
Reloading the full contents of a database:
- Unzip the backup file you wish to use.
- Open it up and pull out only the information that you will need.
- Save this text file.
- Use the following command to feed back in the contents of a text file:
mysql --verbose --user=XXXXXXXX --password=XXXXXXXX DB_NAME < PATH_TO_SQL_DUMP_FILE.SQL
Django: Dump your database contents to(SQL data) into an xml file
To dump all the data in your Django project's db into a nice xml fixture, just run the following command:
Update:python manage.py dumpdata --format=xml APP_NAME > SOME_FIXTURES_FOLDER/APP_NAME/initial_data.xml
As Fabi[1] correctly (and violently jeje :-P) pointed out, json is much cooler:
python manage.py dumpdata --indent=4data.json
[1] @caffeineGalli at Twitter and his site: http://from-the-cloud.com/
Suscribirse a:
Entradas (Atom)