9951 explained code solutions for 126 technologies


python-mysqlHow do I install MySQL using pip in Python?


Installing MySQL using pip in Python is quite easy and straightforward. The following example code block shows how to do it:

pip install mysql-connector-python

The output of the code will be something like this:

Collecting mysql-connector-python
  Downloading https://files.pythonhosted.org/packages/f8/a8/a1f9b9e5b2f7d5d77b1f7a9e9fcf5a6e6f14a7f3e5a9a25b3b8d9d4eb7c7/mysql-connector-python-8.0.19.tar.gz (11.9MB)
    100% |████████████████████████████████| 11.9MB 2.2MB/s
Installing collected packages: mysql-connector-python
Successfully installed mysql-connector-python-8.0.19

The code consists of two parts:

  1. pip install mysql-connector-python - this part of the code instructs pip to install the MySQL Connector/Python package from the Python Package Index (PyPI).
  2. Downloading https://files.pythonhosted.org/packages/f8/a8/a1f9b9e5b2f7d5d77b1f7a9e9fcf5a6e6f14a7f3e5a9a25b3b8d9d4eb7c7/mysql-connector-python-8.0.19.tar.gz (11.9MB) - this part of the code downloads the MySQL Connector/Python package from the PyPI repository.

After the package is installed, you should be able to use it in your Python code.

Helpful links

Edit this code on GitHub