Results 1 to 5 of 5

Thread: MySQL Connectivity With Python

  1. #1
    Join Date
    Apr 2009
    Posts
    515

    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.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    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.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    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.

  5. #5
    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

Similar Threads

  1. Localhost 10060 error message occurring in MySQL server connectivity
    By Ooopinder in forum Networking & Security
    Replies: 4
    Last Post: 09-05-2011, 10:14 AM
  2. Replies: 4
    Last Post: 13-01-2011, 01:08 AM
  3. Replies: 3
    Last Post: 07-11-2009, 09:36 PM
  4. Download Python 3.0 / Python 3000
    By Amaresh in forum Software Development
    Replies: 6
    Last Post: 24-02-2009, 09:28 AM
  5. Mysql Database Connectivity Issue
    By joquim in forum Networking & Security
    Replies: 1
    Last Post: 26-12-2008, 06:57 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,291,259.86628 seconds with 17 queries