Skip to content
Exercises · Q1

Q.Write the statement to install the python connector to connect MySQL i.e. pymysql.

Punjab PsebTextbookSubjective· 2mImportance★★★★★
40% · 21/53 Questions
✓ Free question

The command pip install pymysql installs the Python package needed to connect Python code to a MySQL database.

This is a straightforward fill-in-the-blank / command question — you are asked for the exact terminal command that installs the pymysql package.

Why pymysql?

Python does not come with built-in MySQL connectivity. To make Python talk to a MySQL database, you need a connector — a library that translates Python method calls into MySQL queries and back. pymysql is a pure-Python MySQL client library that works without any C extensions, making it easy to install on any system.

The standard tool for installing Python packages is pip (Pip Installs Packages). So the command follows the pattern:

pip install <package-name>
Tip

On some systems (especially Linux/macOS), you may need pip3 instead of pip, or use python -m pip install pymysql to ensure you're using the correct Python environment.

The Command

pip install pymysql

Once installed, you can import it in your Python code:

import pymysql

# Then connect to a MySQL database
connection = pymysql.connect(
    host='localhost',
    user='root',
    password='your_password',
    database='your_database'
)
Watch out

A common mistake is to write pip install mysql or pip install mysql-connector — those are different packages. The question specifically asks for pymysql, which is the standard connector used in the CBSE Class 12 Informatics Practices curriculum.

✓Final answer

The correct command is pip install pymysql.

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.