How to connect MySQL DB in Python?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to connect MySQL DB in Python?

How to connect MySQL DB in Python?

This recipe helps you connect MySQL DB in Python

0

Recipe Objective

Have you tried to connect MySQL DB in python ?

So this is the recipe on how we can connect MySQL DB in Python.

Step 1 - Importing Libraries

import sqlalchemy as sa import pandas as pd

Here we have improted pandas and sqlalchemy which will be needed.

Step 2 - Connecting to SQL

We have first used iris dataset for this and passed the information of SQL and applied dataset.to_sql to save the file as SQL. dataset = pd.read_csv("iris.data.csv") engine_str = ( "mysql+pymysql://{user}:{password}@{server}/{database}".format( user = "root", password = "root888", server = "localhost", database = "datasciencerecipes")) engine = sa.create_engine(engine_str) conn = engine.connect() # check whether connection is Successful or not if (conn): print("MySQL Connection is Successful ... ... ...") else: print("MySQL Connection is not Successful ... ... ...") dataset.to_sql(name="irisdata", con=engine, schema="datasciencerecipes", if_exists = "replace", chunksize = 1000, index=False) conn.close()


Relevant Projects

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Human Activity Recognition Using Multiclass Classification in Python
In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.