virtualenv – EnvironmentError: mysql_config not found

So I was setting up virtualenv, during the setup process I was having this very common(!) error when I was trying to install MySQL-python. The solution is bit tricky. Though I found solution like, setting PATH on .profile, but actually that might work for normal installation.

I am on Mac OS 10.6.8 and for me the mysql_config file was in /usr/local/mysql/bin/ directory.

Edit the /bin/activate file from the virtualenv directory and add the following lines,

export PATH

then run the following command

source virtualenvDirectory/bin/activate

this will change your path to virtualenv’s bin directory.

now try to install MySQL-python again.

and to undo the changes to $PATH

deactivate virtualenvDirectory/bin/activate

and tada!!!

Setting up mysql and phpmyadmin on Mac OSX

well, I have been using MAMP for quite a long time. It’s a nice app. But then again, if I have native support on my own OS why use an third party app. Heh, actually I need this for some other reason.

Anyway, I am using Snow Leopard (little old though, don’t have money to buy the new one :P)

So, first download the latest version of .dmg from here.

Click mysql-5.5.19-osx10.6-x86_64.pkg (you may have different version) and install by following the screen.

Though this is optional, but I recommend to install MySQLStartupItem.pkg and run the MYSQL.prefPane as well. It will give you a MySQL panel on the System Preference. From here you can start/stop MySQL and also set for automated start upon server startup.

MySQL is accessible from /usr/local/mysql/bin/mysql

Set MySQL password for later use.

/usr/local/mysql/bin/mysqladmin -u root password SECRET

Installing phpmyadmin

Start Apache from System Preference (enable the web sharing). http://localhost should work now.

In Mac OSX PHP is not enabled by default. So enable PHP from /etc/apache2/httpd.conf by uncommenting the LoadModule php5_module        libexec/apache2/ line.

Download phpmyadmin from here.

Extract the files into /usr/local/ directory and rename it to phpmyadmin

Copy the and rename it to from the phpmyadmin directory.

Create a file into /etc/apache2/other/ and add the following lines

Alias /phpmyadmin /usr/local/phpmyadmin
<Directory /usr/local/phpmyadmin>
    Options Indexes
    Order allow,deny
    Allow from all

Restart Apache from terminal

apachectl restart

Open http://localhost/phpmyadmin/


Install LAMP on ubuntu

Installing LAMP(Linux, Apache, MySQL, PHP) is not that tough now-a-days.

The easiest way
First open the synaptic manager with sudo synapti
then Edit ==> Mark Packages by Task
select LAMP server from the list and click OK.

Another easy way
go to terminal and type
sudo tasksel

press space bar to select and then tab to <ok>
Follow the screen.

One line command setup
go to terminal and type
sudo apt-get install lamp-server^
N. B the character ‘^’ is not a typo
Follow the screen, it’ll ask to change password for the root user of MySQL database.

Now. test Apache. Open a browser and type http://localhost/

if you see this, you are done with you apache installation.

test PHP installation. open terminal and type
sudo vim /var/www/test.php
save the file.
again, sudo /etc/init.d/apache2restart
now, open browser and try http://localhost/test.php

you see this, means your PHP installation is completed.

Test MySQL setup
go to terminal and type
mysql -u root -p

you see this, ahhhh….you are done with the famous LAMP installation 😀

For phpmyadmin setup try this

JDBC – Java Database Connectivity

Java Database Connectivity (JDBC), which is a standard Java API for database-independent connectivity between the Java programming language and a wide range of databases.
It has four major parts:

  • Making a connection to a database
  • Creating SQL or MySQL statements
  • Executing that SQL or MySQL queries in the database
  • Viewing and modifying the resulting records

Step 1

Open a new Java Application –> Right-click on the project –> select Properties. Then from the left menu select libraries.

selecting JAR file
selecting JAR file

Select Add JAR/Folder.

select the mysql-connector-java-5.1.6-bin.jar file. Which can be found in the Netbeans folder. For Mac, it is in /Application/Netbeans/Netbeans 6.8/contents/Resources/ide12/modules/ext/mysql-connector-java-5.1.6-bin.jar

Now are able to use the JDBC in your program frequently 🙂

Step 2

Here, I’ll be talking about connecting to a MySQL database. But it can be used for other cases also.

Selecting a right driver will be another major task.

For ORACLE the driver will be oracle.jdbc.driver.OracleDriver

For DB2 the driver will be

For Sybase the driver will becom.sybase.jdbc.SybDriver

import java.sql.*;

Load the driver class using Class.forname(com.sybase.jdbc.SybDriver)

Define the data source for the driver String sourceURL = “jdbc:mysql://URL/database_name”

Create a connection through the DriverManager

Connection databaseConnection = DriverManager.getConnection(sourceURL)

All this should be in a try-catch block.