Error connecting to MySQL from Python

Jussi Piitulainen jpiitula at ling.helsinki.fi
Sat Oct 12 12:46:49 EDT 2013


carlos.ortiz.asm at gmail.com writes:

> So I wrote my method like this:
...
>       cnxOMC = mysql.connector.connect(user,
>                                        password,
>                                        'localhost',
>                                        database)
...
> the following code executes nice and smooth:
...
>       cnxOMC = mysql.connector.connect(user="root",
>                                        password='PK17LP12r',
>                                        host='localhost',
>                                        database='TESTERS')

You pass the hardcoded parameters as keyword arguments, unlike in the
version that doesn't work. Maybe that is the difference. Try this:

       cnxOMC = mysql.connector.connect(user=user,
                                        password=password,
                                        host='localhost',
                                        database=database)

It only looks funny. In "user=user" the first "user" is a parameter
name, the other is the variable in your code.

Try help(mysql.connector.connect) at the interactive prompt, or
otherwise check the documentation.



More information about the Python-list mailing list