Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 14-04-2009
Member
 
Join Date: Apr 2009
Posts: 511
MySQL Connectivity With Python

How do we configure python for use with mysql? After installing the MySQL-python-0.9.2.tar.gz the problem arises that the _mysql.c error that at
line 1243 that "@" undefined symbol and /usr/include/mysql.h:4:223:5"@" is not valid in if expression like all errors are out when i give the command python setup.py build.

Please help me and give some suggestion that i can install the connection in python and mysql.
Reply With Quote
  #2  
Old 14-04-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: MySQL Connectivity With Python

You require the MySQLdb module for connecting to mysql server using the python code. This module is used for firing queries to the database server and handling of result sets from python code.First of all, check if the module is available or not :

jayant@jayantbox:~$ python
Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb;
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named MySQLdb
>>>

If you are getting an importError, then the module is not installed. Download the source files from http://sourceforge.net/projects/mysql-python

Compile and install the module:

tar -xvzf MySQL-python-1.2.2.tar.gz
.
.
cd MySQL-python-1.2.2/
.
.
python setup.py build
.
.
sudo python setup.py install
.
.
Installed /usr/lib/python2.5/site-packages/MySQL_python-1.2.2-py2.5-linux-x86_64.egg
Processing dependencies for MySQL-python==1.2.2

I also faced this problem during the build process. The setup process was unable to find the mysql_config program in the path. So i did
export PATH=/usr/local/mysql/bin:$PATH
And then i ran the build process and it was successful.
Reply With Quote
  #3  
Old 14-04-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: MySQL Connectivity With Python

Try importing the MySQLdb module in the python environment

jayant@jayantbox:/usr/share/python$ python
Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.5/site-packages/PIL/__init__.py", line 19, in

File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in
File "build/bdist.linux-x86_64/egg/_mysql.py", line 6, in __bootstrap__
ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
>>>

If the library is not able to locate shared library, add the library path to the LD_LIBRARY_PATH environment variable

export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH

And then try

jayant@jayantbox:~$ python
Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>

Now importing the mysqldb module has been successful.
Reply With Quote
  #4  
Old 14-04-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: MySQL Connectivity With Python

Python comes with a bunch of different modules that allow you to add new capabilities to your Python scripts. One of the more useful ones is the MySQLdb module, which allows you to execute SQL queries on a MySQL database through your Python application.
Reply With Quote
  #5  
Old 14-04-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: MySQL Connectivity With Python

Now if you are having issues with setting the environment variable LD_LIBRARY_PATH and you have root access then you need to export this variable in /etc/profile file. But if you do not have the root access you can simply import the variable in your local .bash_profile file.

Add the following line at the end of either file "/etc/profile" or "/home/homedir/.bash_profile"

LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "MySQL Connectivity With Python"
Thread Thread Starter Forum Replies Last Post
Localhost 10060 error message occurring in MySQL server connectivity Ooopinder Networking & Security 4 09-05-2011 10:14 AM
Unable to install MySQL and MySQL Workbench on Linux mint 10 Zared Windows Software 4 13-01-2011 01:08 AM
Mysql Error : Can't connect to local mysql server through socket ' var lib mysql mysql.sock' 2 roshan45 Software Development 3 07-11-2009 09:36 PM
Download Python 3.0 / Python 3000 Amaresh Software Development 6 24-02-2009 09:28 AM
Mysql Database Connectivity Issue joquim Networking & Security 1 26-12-2008 06:57 PM


All times are GMT +5.5. The time now is 11:31 AM.