Forums

web2py MySQL connection string doesn't work

I'm sure there is something obvious (to others) about why this won't work, but I'm trying to run the cpdb.py script, which needs connection strings for both the source & target; the target in this case is the default mySQL database that came with my account.

The string I'm using is of the format:

mysql://<username>:<password>@mysql.server/<username>$default

If I try the database password I assigned from the Databases tab under the dashboard, I get a 1044 error. If I use the password that appears when I SHOW GRANTS, I get a 1045 error (which is the same that I get if I use a completely bogus password).

  • Scott

Which password are you using there? It should be the one you set up on the "Databases" tab, not the one you use to log in to PythonAnywhere. I believe that the thing you see when you SHOW GRANTS is an md5 hash of the former, so it won't work (though I may be wrong on that).

If I try the database password I assigned from the Databases tab under the dashboard, I get a 1044 error.

Very odd. What happens if you run this in a bash console:

mysql -upawprinttrials -p -hmysql.server 'pawprinttrials$default'

...and enter your database password?

02:43 ~/web2py2 $ mysql -upawprinttrials -p -hmysql.server 'pawprinttrials$default'                                                                        
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1336730
Server version: 5.1.63-log MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

But if I try the script with the same password, I get:

EXCEPTION: could not make a copy of the database
Failure to connect, tried 5 times:
Traceback (most recent call last):
  File "/home/pawprinttrials/web2py2/gluon/dal.py", line 7766, in __init__
    self._adapter = ADAPTERS[self._dbname](**kwargs)
  File "/home/pawprinttrials/web2py2/gluon/dal.py", line 2657, in __init__
    if do_connect: self.reconnect()
  File "/home/pawprinttrials/web2py2/gluon/dal.py", line 647, in reconnect
    self.connection = f()
  File "/home/pawprinttrials/web2py2/gluon/dal.py", line 2655, in connector
    return self.driver.connect(**driver_args)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1044, "Access denied for user 'pawprinttrials'@'%' to database 'pawprinttrials'")

Hmm. That looks like it's trying to open the database 'pawprinttrials' rather than 'pawprinttrials$default'. Are you calling the Python script with the database connection string from a Bash command line? If so, you'll need to put single quotes around the database name (as in the mysql command line) because otherwise Bash will try to expand the '$default' as an environment variable.