The detailed process of using MySQL database with Python 3.4 is as follows Windows version: Windows7-64bit 1. MySQL Community Server installation: 1.mysql-5.7.17-win64.zip download URL: https://dev.mysql.com/downloads/mysql/ For the Windows version, I chose mysql-5.7.17-win64.zip for download. The two ZIP files at the bottom are for testing and can be ignored. If you are not logged in, you can choose to download directly. 2. Unzip the ZIP file and extract it to the directory where you want to install it. 3. Configure environment variables. Find the location of the decompressed file, the screenshot is as follows: The variable value I configured is D:\MySQL\mysql-5.7.17-winx64\bin. Note that a semicolon - ";" needs to be added in front of this. The screenshot is as follows: 4. Configure the my.ini file. Copy the my-default.ini file to the current directory and rename it to my.ini. As shown below: Open the my.ini file and configure it as follows (Note: the path setting needs to be escaped with the escape character "\", or use a backslash "/", and comment out the last line): 5. Initialize the database and configure related information (the command execution order must be correct, otherwise initialization will fail) (1) Run the Windows command line cmd as an administrator and enter the bin directory of the installation directory as follows: (2) Initialize the data directory: Enter the command (to create a root user without a password): mysqld --initialize-insecure At this time, a data folder will be generated under the mysql folder, which contains some folders and files, which indicates that the initialization is successful. (3) Register MySQL service: Enter the command: mysqld -install The following figure appears, indicating that the registration is successful. (4) Start the MySQL service: Enter the command: The following figure appears, indicating that the startup is successful. (5) Set password: Enter the command: mysqladmin -u root password password (6) Log in to mysql using the password: Enter the command: mysql -u root -p The final screenshot is as follows: At this point, MySQL configuration is complete. If you want to exit the MySQL service, use the command: exit If you want to remove the MySQL service, use the command: mysqld --remove 2.Connector/Python installation: The command window (cmd) uses the following command: easy_install pymysql3 After python3, MySQLdb was replaced by pymysql. Depending on the version used, different connectors are installed. Note: This needs to be used after python 3.4 is installed. The results are as follows: 3. Test The test.py program is written as follows: import pymysql conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='meditation',db='mysql') cursor = conn.cursor() cursor.execute ("SELECT VERSION()") row = cursor.fetchone() print("MySQL server version:", row[0]) cursor.close() conn.close() Run test.py to view the results, indicating that the configuration is successful. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Automatically log out inactive users after login timeout in Linux
This article describes the MySQL transaction mana...
Table of contents introduce Link start Continue t...
1. The window size opened by the HTML hyperlink C...
Table of contents 01. Use useState when render is...
*Create a page: two input boxes and a button *Cod...
Due to the initial partitioning of the system, th...
Table of contents 1. Introduction 2. Configuratio...
Docker has many log plug-ins. The default is to u...
Table of contents Hidden Problems Solution to ada...
The effect is as follows: analyze 1. Here you can...
Recently, during the development process, the MyS...
I searched on Baidu. . Some people say to use the...
This article mainly introduces the implementation...
On a Windows server, if you want to back up datab...
This article mainly introduces the analysis of My...