Tools, FAQ, Tutorials:
PyMySQL Package by pypi.org
How to use "pymysql" module from PyMySQL Package produced by pypi.org?
✍: FYIcenter.com
"pymysql" is a Python module in the PyMySQL package
provided by pypi.org for MySQL database connection.
"pymysql" implements "PEP 249 -- Python Database API Specification v2.0" at https://www.python.org/dev/peps/pep-0249/. You can follow this tutorial to try it.
1. Install "PyMySQL" package that contains the "pymysql" module. Do not use the outdated "MySQLdb" package.
fyicenter> pip3 install pymysql ... Successfully installed pymysql-1.0.2
2. Start a Python 3 interactive session and import the "pymysql" module.
fyicenter> python3 Python 3.8.0 (v3.8.0:fa919fdf25) >>> import pymysql >>> pymysql.1.03 '1.0.2'
3. Call the connect() method to establish a connection to a MySQL server with given accessing information. It returns a Connection object representing the established connection.
>>> con = pymysql.connect(host="127.0.0.1", port=3306, ... user="guest", password="retneciyf") >>> print(con) <pymysql.connections.Connection object at 0x107108f40>
4. Use Connection methods and properties to see the MySQL environment.
>>> con.get_server_info() '8.0.17' >>> con.user b'guest' >>> con.charset 'utf8mb4' >>> con.encoding 'utf8'
5. Call select_db() method to set the default database to a database instance that your user name is allowed to use.
>>> con.select_db("test") >>> >>> con.db b'test'
6. Run SQL statements on the connection as shown in next tutorials.
7. Close the connection at the end.
>>> con.close()
⇒ Change Data with PyMySQL Package
⇐ MySQLConnection.cursor() and MySQLCursor.execute()
2021-09-09, 1179🔥, 0💬
Popular Posts:
How To Copy Array Values to a List of Variables in PHP? If you want copy all values of an array to a...
Can Multiple Paragraphs Be Included in a List Item? Yes. You can include multiple paragraphs in a si...
How to create a navigation file like navigation.xhtml for an EPUB 3.0 book? At least one navigation ...
Where to find tutorials on HTML language? I want to know how to learn HTML. Here is a large collecti...
How to validate the id_token signature received from Azure AD v2.0 authentication response? You can ...