example for you to share the specific code of the python3 connection MySQL database for you for your reference. The details are as follows:

 #python3 connects MySQL instance import pymysql "" "import the package that connects MySQL needs, and no installation pymysql needs to be installed with the command line to switch to the installation path of Python. The PIP install pymysql "" connects the MySQL database db = pymysql.connect ("localhost," "," "," "," "," python_conn ", charset ='utf8')" "" "" "" "the five parameters are the host name, username, password, to connect the database name, the character set" "to solve the Chinese chaotic code problem" "use cursor ( Obtain the operation cursor cursor = db.cursor () use the execute () method to execute the SQL statement SQL ='select * from test_conn'cursor.execute (SQL) use fetchone () method to obtain all the data results = Print (SID, name, age, sclass) close the database db.close () 

above is the whole content of this article, I hope to help you, and also hope that you can support a lot of the script home.

you may be interested in: