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
The color matching in website construction is ver...
Table of contents Overview Install Gulp.js Create...
Lock classification: From the granularity of data...
This article mainly introduces the implementation...
Preface Index Condition Pushdown (ICP) is a new f...
Parent File import React, { useState } from '...
When logging in to the stress test, many differen...
Table of contents What happened? When to use Cont...
HTML5 is the next version of the HTML standard. M...
Table of contents 1. Overview 1.1 What is a proto...
How to recursively select all child elements usin...
Preface In the Linux operating system, device fil...
CSS3 can create animations, which can replace man...
This is an article written a long time ago. Now it...
This article mainly focuses on the installation a...