MySQL Forums
Forum List  »  Connector/Python

Windows: connector 8.0.11 does not read "option_files"
Posted by: 7 reeds
Date: April 22, 2018 04:58PM

Hi,

I've been having this problem for a while. The Python connector does not understand the "option_files" connection argument. I have the following situation:

I have a development environment and I sometimes want to drop every table in the dev DB and recreate. Because of my hosting provider I can not drop or add a "database from the command line. I wrote the script below to look for and drop the tables in the database though.

import os
import mysql.connector.django

DBI = mysql.connector.connect(
option_files=os.path.join(os.path.expanduser("~"), ".my.cnf"),
option_groups="membersdev"
)

cursorFind = DBI.cursor()
cursorDrop = DBI.cursor()

query = """
select TABLE_NAME
from information_schema.TABLES
where TABLE_SCHEMA = 'dev_devSite_org'
"""
cursorFind.execute(query)

query2 = """
drop table if exists %s
"""

for (tableName) in cursorFind:
print(tableName)
cursorDrop.execute(query2, tableName)

cursorDrop.close()
cursorFind.close()

DBI.close()

This script works fine on the linux dev machine. It fails on Windows. I get the stacktrace:

Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\mysql\connector\connection_cext.py", line 176, in _open_connection
self._cmysql.connect(**cnx_kwargs)
_mysql_connector.MySQLInterfaceError: Can't connect to MySQL server on '127.0.0.1' (10061)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\pydevd.py", line 1664, in <module>
main()
File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\pydevd.py", line 1658, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\pydevd.py", line 1068, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/karres/PycharmProjects/CIAMembers/misc_scripts/db_delete.py", line 16, in <module>
option_groups="membersdev"
File "C:\Program Files\Python36\lib\site-packages\mysql\connector\__init__.py", line 148, in connect
return connect(**new_config)
File "C:\Program Files\Python36\lib\site-packages\mysql\connector\__init__.py", line 182, in connect
return CMySQLConnection(*args, **kwargs)
File "C:\Program Files\Python36\lib\site-packages\mysql\connector\connection_cext.py", line 78, in __init__
self.connect(**kwargs)
File "C:\Program Files\Python36\lib\site-packages\mysql\connector\abstracts.py", line 736, in connect
self._open_connection()
File "C:\Program Files\Python36\lib\site-packages\mysql\connector\connection_cext.py", line 179, in _open_connection
sqlstate=exc.sqlstate)
mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (10061)

It should not be trying to connect to localhost via networking because the config file says to use a socket:


[membersdev]
socket=MySQL
protocol=pipe
user=devsiteorg
password=********
database=dev_site_org

I know that the config file *works* from the windows commend line because I can start the mysql client in a command window and specify the default file. the "client" part of the config file is the same as the one above.

Options: ReplyQuote


Subject
Written By
Posted
Windows: connector 8.0.11 does not read "option_files"
April 22, 2018 04:58PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.