Python MySQL Connector: Why do I get different error messages depending on user for the same error?

398
January 21, 2018, at 07:01 AM

I am connecting to a mysql database to get some data. It works fine, but I am trying to build in error checking in the event something goes wrong.

Here is the test code (without error checking):

conn = mysql.connector.connect(
         user='pool',
         password='password',
         host='127.0.0.1',
         database='emsdb')
conn.close()

When I change the user to an incorrect user, I get the following error:

mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'pooll'@'localhost' (using password: YES)

Which is what I expected. Same when I feed it the wrong host:

mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'haarp:3306' (-2 Name or service not known)

But when I intentionally feed it the wrong database name I am getting this error:

mysql.connector.errors.ProgrammingError: 1044 (42000): Access denied for user 'pool'@'%' to database 'emsdbb'

instead of this error (which I see correctly but only when using the root user):

mysql.connector.errors.ProgrammingError: 1049 (42000): Unknown database 'emsdbb'

So my questions is why would the 'pool' user get a different error than the 'root' user for the exact same error (ie - wrong database)?

I want the actual, correct error to be returned, but I don't want to use the 'root' user to make that happen.

Thanks

READ ALSO
Scrapy & MySQL database:

Scrapy & MySQL database:

I'm trying to scrape a website with Scrapy and store the information to a MySQL database

210
New mac (High Sierrra), can't reach localhost, local client sites or phpmyadmin

New mac (High Sierrra), can't reach localhost, local client sites or phpmyadmin

I just upgraded to a new mac, but can't reach localhost, local client sites and phpmyadminI'm sure I missed something, but so far, I've verified that:

134
Best way to write a MySQL Python Class?

Best way to write a MySQL Python Class?

I've always written a database class which has methods for each query I need

168
Complex MySQL queries relating two dictionary tables and frequency of occurrence in a third relational table

Complex MySQL queries relating two dictionary tables and frequency of occurrence in a third relational table

I have a database that catalogs medieval anthologiesIn one table each anthology is given a unique ID

113