An mysql-python tutorial?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dfenestr8

    #1

    An mysql-python tutorial?

    Hi.

    Been told by the admin of my (free!) server that he'd rather I should
    learn to use mysql if I want to continue writing cgi scripts there.

    Not even sure exactly what mysql is.

    Is there a simple tutorial anywhere on the web about using python + mysql?
  • Kartic

    #2
    Re: An mysql-python tutorial?

    Dfenestr8 said the following on 1/28/2005 5:21 PM:[color=blue]
    > Hi.
    >
    > Been told by the admin of my (free!) server that he'd rather I should
    > learn to use mysql if I want to continue writing cgi scripts there.
    >
    > Not even sure exactly what mysql is.
    >
    > Is there a simple tutorial anywhere on the web about using python + mysql?[/color]

    Did you try googling?

    There are two items in the very first page that should be of use to you.
    One is the Python-MySQL module, which you should have installed.

    http://sourceforge.net/projects/mysql-python

    There is an examples directory that has some concrete stuff to help you
    learn.

    Another hit is a basic tutorial, simple to follow and learn :-


    And here is one more site, good stuff here too:-


    You might also want to check the "Charming Python" pages at IBM.com but
    I dont know if they have articles covering mysql.

    HTH!

    Thanks,
    --Kartic

    Comment

    • EuGeNe

      #3
      Re: An mysql-python tutorial?

      Dfenestr8 wrote:[color=blue]
      > Hi.
      >
      > Been told by the admin of my (free!) server that he'd rather I should
      > learn to use mysql if I want to continue writing cgi scripts there.
      >
      > Not even sure exactly what mysql is.
      >
      > Is there a simple tutorial anywhere on the web about using python + mysql?[/color]

      http://www.devshed.com/c/a/Python/My...y-With-Python/

      that one put me on the right track (I think ;)

      --
      EuGeNe

      [----



      ----]

      Comment

      • Andy Dustman

        #4
        Re: An mysql-python tutorial?

        It's a pretty good tutorial, thought I would recommend you forget about
        the fetchone() example. The example below demonstrates three additional
        features that will make your life easier: MySQL option files, tuple
        unpacking, and cursors as iterators (fourth feature: the default host
        is localhost; this is rapidly turning into the Spanish Inquisition
        sketch):

        #!/usr/bin/python
        import MySQLdb
        db = MySQLdb.connect (db="db56a", read_default_fi le="~/.my.cnf")
        cursor = db.cursor()
        cursor.execute( "SELECT name, species FROM animals")
        for name, species in cursor:
        print name, "-->", species

        (I also shy away from doing SELECT *; what if your schema changes?)
        (If the indentation is hosed, blame Google Groups.)

        Comment

        • Dfenestr8

          #5
          Re: An mysql-python tutorial?

          On Sat, 29 Jan 2005 06:41:37 +0000, Kartic wrote:

          [snip][color=blue]
          > And here is one more site, good stuff here too:-
          > http://www.kitebird.com/articles/pydbapi.html
          >[/color]

          Hi.

          I followed the instructions there, tried out the test script they
          recommend.

          Can you tell me why this command, in the python interpreter:
          [color=blue][color=green][color=darkred]
          >>>conn = MySQLdb.connect (host = "localhost" , user = "flipper", passwd =[/color][/color][/color]
          "[hidden]", db = "mydb")

          produces this error:
          Traceback (most recent call last):
          File "<stdin>", line 1, in ?
          File "/usr/lib/python2.3/site-packages/MySQLdb/__init__.py", line 63, in Connect
          return apply(Connectio n, args, kwargs)
          File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py" , line 115, in __init__
          self._make_conn ection(args, kwargs2)
          File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py" , line 41, in _make_connectio n
          apply(super(Con nectionBase, self).__init__, args, kwargs)
          _mysql_exceptio ns.OperationalE rror: (1045, "Access denied for user:
          'flipper@localh ost' (Using password: YES)")

          I also have MySQL installed, and tried setting up the user flipper with
          the mysql client, as per the instructions here:

          Comment

          • Andy Dustman

            #6
            Re: An mysql-python tutorial?

            It definitely looks like an access control problem; recheck your grants.

            Comment

            Working...