Learn Python
Learn Data Structure & Algorithm
Learn Numpy
Learn Pandas
Learn Matplotlib
Learn Seaborn
Learn Statistics
Learn Math
Learn MATLAB
Learn Machine learning
Learn Github
Learn OpenCV
Learn Deep Learning
MySQL Introduction
MySQL Setup
MySQL Operators
MySQL Basic Works
MySQL Create Table
MySQL insert and get values
MySQL Condition
MySQL GROUP BY
MySQL Case
MySQL sorting and calculate avg,sum,count
MySQL Update
MySQL Time
MySQL String
MySQL Rollback & Commit
MySQL Join and Concatenate
MySQL Index
MySQL Date
MySQL View
MYSQL With Python
Learn MongoDB
Learn Web scraping
Learn Excel
Learn Power BI
Learn Tableau
Learn Docker
Learn Hadoop
To connect mysql database with python use a library named mysql.connector.
To download and install we have to give command:
To command prompt:
pip install mysql-connector-python
To jupyter notebook and spyder:
!pip install mysql-connector-python
All the syntax of queries or code that you had already learned in SQL will be same in python.
For example, if you create a database, you will write create database database_name; in SQL.
You will also write the same query or code in python but here you have to do some work before.
Here you have use a cursor function and you have to store it in a variable.
Example:
my_cursor=connection.cursor()
Here the connection is that variable name where you connected python with MySQL.
Now you will write MySQL query or code and will store it in a variable or you can directly write inside that
function where you will pass this query variable.
Example:
query="create database My_database;"
Then to execute we write:
cursor_stored_variable_name.execute(variable name where we stored query")
or,
cursor_stored_variable_name.execute(" sql query or code")
Example: