python 3.x MySQL database connection driver download and tutorial

Note that this article is written, related to the MySQL database 8.0 or later, if the following updated version wait! ! !

  First MySQL database to find the official website to download driver, I give this URL: https: //dev.mysql.com/downloads/connector/python

You will see this screen go after

 

 

 There select the operating system and download formats; generally we need to download is a compressed file format package, but this interface is installed, you need to select download files in Figure :( tutorial only temporarily Window tutorial)

 

 

 

Window System Select download compressed zip format; FIG download is complete decompression:

 

 

 

The MySQL driver package python download is complete.

How to add drive and use PyCharm in:

In software PyCharm set to add a database, click Database select Settings button, and then pop up a window to find the MySQL database in the left point into the menu list, select MySQL8.0 or later and then point OK, the following interface will come out to fill in the following UserhePassword Figure:

 

 

 

 Adding MySQL driver in PyCharm, select the file on the menu bar to find the setting to go find

 

 

 In this third-party library found pip go in search, double-click the selected MySQL mysql-connector-python then click Install install Package:

 

 

 Installation is black.

Next is the test drive:

Create a database connection

Can connect to the database using the following code:

demo_mysql_test.py:

Import MySQL . Connector mydb = MySQL . Connector . Connect ( Host = " localhost " ,       # database host address the User = " yourusername " ,    # database user name passwd = " yourpassword " # database password ) Print ( mydb )


 
 
    


 

Compile the results:

 

 

Complete the connection

If you need to develop a document mysql driver API URL: https: //dev.mysql.com/doc/connector-python/en/

 

Guess you like

Origin www.cnblogs.com/Zeng02/p/11616865.html