Python MySQL connection
Download & Install MySQL with Workbench and creating database with sample student table with records
Database Management using Python
| BLOB||Managing MySQL Blob Data type |
| connection||Python MySQL connection string|
| create||Create table by Query and showing structure|
| rowcount||Number of rows affected due to Query|
| error||Capturing Error in MySQL Query|
| Collect records||Select Query to get records from database table |
| Add record||Using sqlalchemy to Insert record to database table|
| Add record||Insert Query to add record to database table|
| Update record||Update Query to update records of a database table|
| Delete record||Delete records of a database table|
| read_sql||Using MySql records to create Pandas DataFrame |
| mysqlclient||Using sqlalchemy and create_engine to manage MySQL |
| pickle||How to Pickle MySQL table and restore records. |
Installing MySQL connection from Anaconda
Download & install Anaconda with Python by using mysqlclient to connect to MySQL database server
Before this you must have MySQL database running and keep your connection userid and password with your database name ready.
We need to install MySQL connector to connect from Python to MySQL database.
Inside Anaconda goto
Environment at your left side navigational menu
Middle you can see
From Base root select
You will reach the Anaconda terminal where you can install any package . Just enter this line at the prompt to install MySQL connector.
This will install your MySQL connector by downloading packages from the internet. Now it is time to check the connection.
conda install -c anaconda mysql-connector-python
MySQL Connecting string
MySQL connection using SQLAlchemy
For updating the database you need to use sqlalchemy and its create_engine
Here is the code to get the connection by using sqlalchemy
If you are getting error message like this.
from sqlalchemy import create_engine
engine = create_engine("mysql+mysqldb://userid_here:password_here@localhost/db_name")
my_conect = engine.connect()
No module named 'MySQLdb'
then you need to install mysqlclient.
Open your Anaconda terminal as explained above and then enter
pip install mysqlclient
To check the installation
pip show mysqlclient
pip install sqlalchemy
To check the installation
pip show sqlalchemy
MySQL & SQLAlchemy
Python to MySQL database connection by SQLAlchemy with error handling using try except blocks
Google Cloud & MySQL
Using Python we can manage MySQL database of google Cloud.
Managing MySQL database at Google cloud
Here is a list of Queries you can execute using the above learning and display the outcome.
List of Queries
Download .zip file with SQL dump and .ipynb files
of Video Tutorials
This article is written by plus2net.com team.