| Bug #111209 | mysql.connector.connect fails if I specify the database name | ||
|---|---|---|---|
| Submitted: | 31 May 2023 5:04 | Modified: | 3 Jun 2023 18:55 |
| Reporter: | Vijaya Krishna Kasula | Email Updates: | |
| Status: | Can't repeat | Impact on me: | |
| Category: | Connector / Python | Severity: | S2 (Serious) |
| Version: | OS: | Windows | |
| Assigned to: | CPU Architecture: | x86 | |
[31 May 2023 6:36]
MySQL Verification Team
Hello Kasula,
Thank you for the report and test case.
Could you please provide exact python test script which is failing along with the error message? I quickly tried(had to alter a bit to make it work) with the provided test case but not seeing any issues on Windows. Thank you.
-- regardless of commented or un commented the line database=data['database']
import mysql.connector
import sys
import platform
print("OS: {} {}".format(platform.system(), platform.release()))
print("Python:", format(sys.version))
driver = mysql.connector
print("Driver: {} {}".format(driver.__name__, driver.__version__))
data = {"host": "localhost", "user": "root", "password":"mysql123","port":3306, "database": "sakila"}
con = mysql.connector.connect(
host=data['host'],
user=data['user'],
password=data['password'],
port=data['port'],
# database=data['database'],
use_pure=True
)
print(con)
cur = con.cursor()
cur.execute(f"use {data['database']};")
cur.execute('SHOW TABLES;')
print(len(cur.fetchall()))
-
OS: Windows 10
Python: 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
Driver: mysql.connector 8.0.33
<mysql.connector.connection.MySQLConnection object at 0x000001CFFE54F990>
23
Press any key to continue . . .
regards,
Umesh
[31 May 2023 11:20]
Vijaya Krishna Kasula
Hi Umesh, I just had the dictionary data defined in my code apart from what I gave in the bug report. That was the minimal code I used to trigger the bug. My DB host is remote only visible if I connect to my Work VPN. Hence, I can not give that to you to reproduce the bug. Is there any other way I can demonstrate the bug with some remote host that yu and I can connect to? Krishna
[3 Jun 2023 18:55]
Vijaya Krishna Kasula
Hi Umesh Is there anything I can do to help you reproduce the bug. Krishna

Description: The following simple Python code works fine on WSL and Windows, but it fails when I specify the database in the call to the `connect` function (uncomment the `database=` line). ``` Python import mysql.connector con = mysql.connector.connect( host=data['host'], user=data['user'], password=data['password'], port=data['port'], # database=data['database'], use_pure=True ) print(con) cur = con.cursor() cur.execute(f"use {data['database']};") cur.execute('SHOW TABLES;') print(len(cur.fetchall())) ``` Works fine on Windows and WSL If I uncomment the commented line Fails on Windows but still works fine on WSL or Linux etc. How to repeat: Python version: Python 3.11.2 MySQL version: Ver 8.0.33 for Win64 on x86_64 - for MySQL 8.0.33 (MySQL Community Server (GPL)) mysql.connector version: 8.0.33 > python script.py