Menu

mysql.sock and NameError

Help
2001-10-29
2012-09-19
  • Justin Kelly

    Justin Kelly - 2001-10-29

    Hi,
    I'm using Python2.1 and MySQL-3.22.32 on RedHat 6.2. MySQL is under /usr/src... When I import MySQLdb from the command prompt  I get the following message:
    File "<stdin>", line 1, in ?
    File "/usr/local/lib/python2.1/MySQLdb.py", line 27 in ?
    type_conv = {FIELD_TYPE.TINY:int,
    NameError: name 'FIELD_TYPE' not defined
    If I import MySQLdb again no errors are rased. Any ideas what I'm doing wrong?

    Also I then typed db=MySQLdb.connect('','')
    and I get an OperationalError:2002,
    Cant connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)"
    mysql.sock is in /tmp
    can I change where MySQLdb looks for this or should I reinstall MySQL

     
    • Andy Dustman

      Andy Dustman - 2001-10-29

      You don't say what version of MySQLdb you have. If it's an error in MySQLdb.py, you either have a pre-0.9.0 version, or you installed 0.9.0+ over an older version. MySQLdb became a package as of 0.9.0, so if you are using 0.9.0 or newer, get rid of MySQLdb.py.

       
    • Justin Kelly

      Justin Kelly - 2001-11-13

      Thanks Andy, that gor rid of the first problem but the second remains:
      I've installed MySQL-python-0.9.1 with Python2.1 and MySQL-3.22.32 on RedHat 6.2. MySQL is under /usr/src...
      I type db=MySQLdb.connect('','')
      and I get an OperationalError:2002,
      Cant connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)"

      mysql.sock is in /tmp
      can I change where MySQLdb looks for this?

       
    • Justin Kelly

      Justin Kelly - 2001-11-16

      It seems that if you install MySQL as a binary you get a different file structure than you do if you install MySQL as a source/RPM. in the latter the .sock is in '/var/lib/mysql/mysql.sock' in the former it's in '/tmp/mysql.sock'
      I'm trying to figure out how MySQLdb 0.9.1 gets it's mysql.sock reference. I think it comes from _mysql.c ???. I have a binary installation with the .sock in /tmp/ but MySQLdb always looks in '/var/lib/mysql/mysql.sock' I've also set the MYSQL_UNIX_PORT env variable to /tmp/mysql.sock in the hope that MySQLdb uses it ? anybody know where to go from here?

       
    • Justin Kelly

      Justin Kelly - 2001-11-16

      Just to let anyone with this problem know, setting  MYSQL_UNIX_PORT did the job!

       
    • Anonymous

      Anonymous - 2003-04-23

      how to change the MYSQL_UNIX_PORT env variable??
      where is it?

      I used the other way to connect to MySQL when my mysql.sock is not in /var/lib/mysql too.
      Add the parameter unix_socket in _mysql.connect() will work successfully

      but I suggest this way may annoy me a lot because I need remember the right path of mysql.sock when I need to connect mysql everytime
      and if scripture need to move to another platform.....this will induce a big problem...

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.