Applications are being developed on Python nowadays. Developers usually prefer the operating system platform based on their convenience. Usually, developers are used to the command line terminal, Linux is the platform for them.
Developing applications in Python has advantages over handling complexity in a simpler manner. There are scenarios where Python applications need connection with MySQL.
To establish connectivity on the Linux platform, MySQL should be installed and set up properly.
When the application logic is built in Python and the data is stored in MySQL, Python applications need connectivity to pull and push data to and from the MySQL database.
Get MySQL Installed on Linux [Step by Step]
For the purpose of installation we have taken Ubuntu as an Linux distro. Most of the steps would be same for any Linux distro except few commands. Please comment below if you want me to write a tutorial for any specific Linux distribution.
- The terminal window on Linux needs to be open.
- Enter and execute the command – Alternatively you can download it from https://dev.mysql.com/downloads/mysql/, from operating system drop-down select Linux
sudo apt install mysql-server
- The process of connecting to the MySQL downloadable is initiated.

- Make sure there is enough hard disk space (245 MB) as mentioned before starting the installation process.

- Type y to start connecting to the downloadable.
- The downloading and installation process starts.
- Once completed, you shall see the “done!” text.

- To check MySQL installed successfully, enter and run the below command.
mysql --version
- The version shall be displayed as below.

- For security purposes, set the password to access MySQL. Use the following command for setting up the password.
sudo mysql_secure_installation
- Press Y to continue.

- Setup the level of password to be set. A screen asking you the level shall be shown as below.

- Press 0 (LOW) for easy to remember the password.

- The next is to enter the new password and re-enter the same password to be set.
- Press Y to continue.
- Again, press Y where it is asking the user to remove anonymous users.
- To remove the test database and privileges, keep pressing Y on the prompts.

- You are all set with MySQL installed.
Also read:
- How to install Python on Chromebook
- How to install Kali Linux on Mac
- How t install MySQL on Mac for Python
- How to install MySQL on Windows for Python
- Best Linux Distros for gaming
- How to replace Chrome OS with Linux
- Debian vs Ubuntu
- How to install Python IDLE in Linux
Install MySQL Connector for Python
Pip is a package manager that allows the user to install Python packages easily. The steps to install pip and then MySQL connector are stated here.
- Start the terminal window.
- Enter and run the command :
sudo apt -get install python3 -pip
- Make sure that the system has enough space to install pip. Press Y to proceed.

- Post confirmation, download of pip package manager starts.

- Once done, the unpacking process starts.

- Once done, the installation process completes and the command prompt reverts with $.

- The next step is to install MySQL connector through pip.
- Enter the command –
pip install mysql-connector -python
- ENTER to execute the command. The process downloading the package starts.

- Installation starts and once completed, the user gets to see a success message.

- Verify that MySQL works with Python. To do so:
- Create the test.py file in the code editor.
- Enter the text below in the .py file.
import mysql.connectorprint(“Connector version : {0}” .format(mysql.connector.__version__))
- On the terminal, run this command:
python test.py
- You shall see the output as below.
Connector version : 8.0.17
Takeaway
After performing all the steps above, the developer will be easily able to connect to MySQL and fetch the data in the Python application and push data to MySQL using the MySQL connector.