MYSQL AND CONNECTOR/PYTHON
MySQL provides a connector/Python API as another mechanism for connecting to a MySQL database. This section contains some simple Python code samples that rely on connector/Python to connect to a database and retrieve rows from a database table.
Before delving into the code samples, keep in mind that MySQL 8 uses mysql_native_password instead of caching_sha2_password. As a result, you need to specify a value for auth_plugin (which is not specified in various online code samples). Here is the error message:
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
The solution is highlighted in the Python code sample in the next section.
Establishing a Database Connection
Listing 4.10 displays the contents of mysql_conn1.py that illustrates how to establish a connector/Python database connection.
LISTING 4.10: mysql_conn1.py
import mysql.connector cnx = mysql.connector.connect(user='root&apos...