[Tutor] Fwd: Connecting to a new mysql database
Alan Gauld
alan.gauld at yahoo.co.uk
Mon Jul 5 20:25:09 EDT 2021
On 06/07/2021 01:05, Alan Gauld wrote:
>> mydb = mysql.connector.connect(
>> host='localhost',
>> user='root',
>> password='xxxxxxxxxxxxxxx',
>> database='sakila')
> When I run this code, I receive error messages.
>> import mysql.connector
>>
>> mydb = mysql.connector.connect(
>> host='localhost',
>> user='root',
>> password='xxxxxxxxxxxxxxx',
>> database='GloCultur')
> Here are the results”
>
> C:\Users\Arthur
> Thomas\AppData\Local\Microsoft\WindowsApps\python3.9.exe"
> D:/GloCulture/Glo_opensesame.py
> Traceback (most recent call last):
> File "D:\GloCulture\Glo_opensesame.py", line 3, in <module>
> mydb = mysql.connector.connect(
<snip>....
</snip> > line 219, in _do_auth
> self._auth_switch_request(username, password)
> File "C:\Users\Arthur
> Thomas\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mysql\connector\connection.py",
> line 318, in _auth_switch_request
> raise errors.get_exception(packet)
> mysql.connector.errors.ProgrammingError: 1049 (42000): Unknown database
> 'glocultur'
>
> Process finished with exit code 1
> I built the GloCultur inside MySQL. It has 8 tables and each has 24
> records. It is in its own directory.
If it says no such database that implies a path issue. I don't know how
MySql derives the location of its databases but I'd start by looking at
that.
You say it works from MySql? How are you running MySql? Is it from the
same folder as you are running python (which defines the CWD for the
process)?
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list