I'm wondering if there is any built-in way in Python to test a MySQL server connection. I know I can use PyMySQL, MySQLdb, and a few others, but if the user does not already have these dependencies installed my script will not work? How can I write a Python script to test a MySQL connection without requiring external dependencies?
-
Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". And more importantly, please read the Stack Overflow question checklist. You might also want to learn about Minimal, Complete, and Verifiable Examples.Morgan Thrapp– Morgan Thrapp2015-07-20 18:55:04 +00:00Commented Jul 20, 2015 at 18:55
-
There is no built-in support for MySQL - the only relational support included in the Python library is from the SQLite database.holdenweb– holdenweb2015-07-20 18:56:27 +00:00Commented Jul 20, 2015 at 18:56
-
@holdenweb You should expand that slightly and make it an answer. As it stands, it is the best answer to this question (unless a suitable dupe target is found).Two-Bit Alchemist– Two-Bit Alchemist2015-07-20 19:01:20 +00:00Commented Jul 20, 2015 at 19:01
-
Done. Thanks for the suggestionholdenweb– holdenweb2015-07-20 19:12:39 +00:00Commented Jul 20, 2015 at 19:12
Add a comment
|
1 Answer
Python distributions do not include support for MySQL, which is only available by installing a third-party module such as PyMySQL or MySQLdb. The only relational support included in Python is for the SQLite database (in the shape of the sqlite3 module).
There is, however, nothing to stop you distributing a third-party module as a part of your application, thereby including the support your project requires. PyMySQL would probably be the best choice because, being pure Python, it will run on any platform and give you best portability.