How to connect to mysql in pycharm community edition?
Question:
I have a fresh install of pycharm community edition 2019.2 on mac 10.13.1
I want to connect to the mysql database I have locally.
I wrote a python file that starts
import mysql.connector
The ‘mysql’ part is underlined red, so I hover over it and get the message ‘no module named mysql – install package mysql’
I click on the link and it says ‘packages installed successfully – installed packages : mysql’
But the ‘mysql’ part of ‘mysql.connector’ remains red and it still says I haven’t installed mysql.
What am I missing? Would hope this would be more intuitive.
Thanks!
Answers:
You need to install mysql-connector-python (you can also install it from project interpreter).
Install The mysql-connector
Here 2 way to install this module in the pycharm community edition.
- pip install mysql-connector-python
- Click file->Setting->Project:Your-Project->Python Interpreter-> + -> Search mysql-connector-python
After installing this module import in your script(Code)
- import mysql.connector
- connection = mysql.connector.connect(host=’localhost’, database=’Your-DatabaseName’, user=’root’, password=’root’)
- if connection.is_connected():
print("Connection Successfully")
I have a fresh install of pycharm community edition 2019.2 on mac 10.13.1
I want to connect to the mysql database I have locally.
I wrote a python file that starts
import mysql.connector
The ‘mysql’ part is underlined red, so I hover over it and get the message ‘no module named mysql – install package mysql’
I click on the link and it says ‘packages installed successfully – installed packages : mysql’
But the ‘mysql’ part of ‘mysql.connector’ remains red and it still says I haven’t installed mysql.
What am I missing? Would hope this would be more intuitive.
Thanks!
You need to install mysql-connector-python (you can also install it from project interpreter).
Install The mysql-connector
Here 2 way to install this module in the pycharm community edition.
- pip install mysql-connector-python
- Click file->Setting->Project:Your-Project->Python Interpreter-> + -> Search mysql-connector-python
After installing this module import in your script(Code)
- import mysql.connector
- connection = mysql.connector.connect(host=’localhost’, database=’Your-DatabaseName’, user=’root’, password=’root’)
- if connection.is_connected():
print("Connection Successfully")