Installing MySQL in Mac and establishing connectivity with Python is simple. Follow the steps in sequence to make a successful connection for MySQL and Python.
Prerequisites to Install MySQL
- Python shall be available
- 500 MB Space for MySQL
- MySQL Installer Package for Mac
- Python SQL Connector for Mac
Install MySQL on Mac for Python
- Go to https://dev.mysql.com/downloads/mysql/. You shall see the list of packages available for Mac.
- Choose Download for DMG archive. (The first option from the top.)
- You will be asked to Sign up. But there is also an option, No thanks, just start my download. Click that link.
- Once downloaded, you will see the package file in the downloads folder.
- Double-click the package file to start MySQL installation. The below pop up asking for permission appears.
- Choose Allow to proceed. The welcome screen shall be shown.
- Say Continue. The license agreement screen is shown.
- Click Continue. The agreement pop up shall appear.
- Choose Agree. The next screen appears to choose Installation type.
- Click Install. The installation process starts.
- When it finishes, it asks to set up password encryption.
- Keep the selected option to continue. Choose Next.
- Set the password for the root user.
- Click Finish. The completion message shall be shown and click Close to complete the installation.
also read:
- Install MySQL on Windows for Python
- How to install Python on Chromebook
- How to fix Chrome memory leak
- How to replace Chrome OS with Linux
- How to fix FireFox memory leak
- How to install Python IDLE in Linux
Start MySQL on mac
- Open System Preferences. You shall see the MySQL icon.
- Click to start the server.
Install pip on Mac
- Open terminal window and type the command
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
- Once downloaded, enter the command below:
python3 get-pip.py
- Wait till installation gets completed successfully.
Download and Install Python Connector
- Once downloaded successfully, go to the terminal window and enter the command.
pip install mysql-connector-python
Import MySQL Connector in Python
To connect to MySQL server using Python, go to Python in terminal and use the connect() method to establish connectivity.
import mysql.connector con = mysql.connector.connect(user='rbm', password='[email protected]', host='127.0.0.1', database='customer') con.close()