How to connect Python to MySQL Workbench


Step-by-Step Guide


1) Download MySQL:

Download MySQL Installer (For Windows only!)

Begin download



For Windows users...

2) How to setup MySQL Installer

  • We are going to show how to download and install MySQL Community Server only...
    • Double click the file and install it
    • Once it has finished installing, you will see this window below and click on the 'Add' option
Click 'Add' option
    • Agree on their License terms and click 'next'
Agree on License Terms

    • Select the Product that you want to install
Select Product

    • Execute the installation and wait for it...Then click 'Next'
Execute the Installation


    • Once the installation is completed, you will see the product configuration page
Product Configuration



    • Select the type of MySQL server  you want then click 'Next'
Select MySQL Server

    • Select the Server Configuration Type
Select the Server Configuration Type

    • Select the Authentication Method and then click 'Next'
Select the Authentication Method 

    • Create new user account and assign a role to the user. Otherwise, you can just key in a new MySQL Root Password and click 'Next'
Create New User Account

    • Configure MySQL Server as a Windows Server. Change the default name if you want and select what account you would like it to run as. Then click 'Next'
Configure MySQL Server as a Windows Server.



    • Last, apply the configuration! Once it's done, click 'Finish'

Apply the Configuration


3) Launch MySQL Workbench

  • Add a new MySQL connection as follows:
Add a new MySQL connection

  • Setup the new connection. Then click 'Test Connection' and enter the root password
Setup the new connection

  • If the connection is successful, you should see the following message. Then click 'OK'
Successful Connection Message

  • Open the new connection
Open the new connection

  • Create a new Schema and name it! Click 'Apply'
Create a new Schema


4) Connect Python to MySQL Database 

  • In the command prompt, key in the following command with the right input 

import mysql.connector cnn = mysql.connector.connect(user='<your input>', password='<your input>',
host='127.0.0.1', database='<your input>') cnn.close()

Comments

Popular posts from this blog

Predict EPL results (Part 2: Neural Network example)

Bias and Variance in Machine Learning