MySQL online course

Start the MySQL Command-Line Interface

Learn how to open Windows Command Prompt, find mysql.exe, connect to a local MySQL Server as root, verify access, and exit safely.

The mysql client is an interactive terminal program used to connect to a MySQL Server. The client and server are separate programs: the client sends SQL statements and administrative commands, while the server stores data, processes requests, and manages databases.

After a successful connection, the client displays the mysql> prompt. At that prompt, you can inspect databases, run SQL statements, and perform server-related tasks. This lesson assumes that MySQL Server is installed on Windows and that you know the MySQL account credentials created during installation.

Open Windows Command Prompt

Windows Command Prompt is the shell where you first enter commands. The MySQL prompt is not available until the client has connected to a server.

  1. Press Windows key + R to open the Run dialog.
  2. Type cmd.
  3. Press Enter.

You can also open Command Prompt or Windows Terminal from the Start menu. In either case, begin by entering commands at the Windows shell prompt.

Locate the MySQL Client

The executable file for the command-line client is normally named mysql.exe. It is commonly stored in the MySQL installation's bin directory, where executable programs are kept.

A typical MySQL Server installation uses a path similar to this one. The version or installation location on your computer may differ:

cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"

The cd command changes the current directory. Once you are in the bin directory, Windows can find mysql.exe without needing its full path.

Another option is to run the executable by using its full path:

"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe" -u root -p

You may also add the bin directory to the Windows PATH environment variable. PATH is a list of directories that Windows searches for executable commands. After adding the MySQL bin directory to PATH, you can run mysql from any Command Prompt location. This configuration is optional for a first connection.

Connect to MySQL

From the MySQL bin directory, run:

mysql -u root -p

The options mean:

  • -u root selects the MySQL account named root.
  • -p tells the client to request the password interactively.

When the client displays a password prompt, type the MySQL root password and press Enter. Password characters are intentionally not displayed: you will not see letters, dots, or asterisks while typing.

The root account is useful as an initial administrative example, but routine application and database work should generally use a dedicated account with only the privileges it needs. See Create a MySQL user for the next step.

Connection options

OptionMeaningExample use

-u — Selects the MySQL user account — -u root

-p — Requests the password interactively — -p

-h — Specifies the server host — -h localhost

-P — Specifies the server port — -P 3306

The basic command assumes that the server is running on the same computer and that the default connection settings work. localhost means the current computer. The common MySQL network port is 3306.

For an explicit local host and port, use:

mysql -u root -p -h localhost -P 3306

The same form can be used for another server by replacing localhost with a host name or IP address and replacing 3306 if the server uses another port:

mysql -u root -p -h db.example.internal -P 3307

For a remote connection, the server must be reachable, the selected port must be open, and the MySQL account must be permitted to connect from the specified host. A correct password alone does not guarantee permission to connect.

Recognize a Successful Login

After authentication succeeds, the client displays information about the connection and then shows:

mysql>

This is the mysql prompt. It means that commands you enter will now be interpreted by MySQL rather than by Windows Command Prompt.

Run this verification query:

SELECT USER(), VERSION();

SQL statements in the interactive client normally end with a semicolon. The query returns the authenticated account identity and the connected server's version. A result confirms that the client is connected and can execute SQL.

Prompt and context guide

Prompt or locationMeaningWhat commands belong there

Windows Command Prompt — Windows is interpreting commands — cd, mysql -u root -p, and other Windows commands

MySQL mysql> prompt — The client is connected and ready — SQL statements such as SHOW DATABASES; and client commands such as exit

MySQL continuation prompt — The previous input is incomplete — Finish the SQL statement, close an unfinished quote or parenthesis, and enter the terminator

Perform Basic Actions After Connecting

List available databases

At the mysql> prompt, enter:

SHOW DATABASES;

The client displays databases that the authenticated account is allowed to see. The list can include system databases and databases created by users.

Check the account and server version

SELECT USER(), VERSION();

USER() reports the account identity used by the connection, while VERSION() reports the server version.

Exit cleanly

When finished, enter:

exit

The MySQL session ends and control returns to Windows Command Prompt. You can also use quit in the interactive client.

This login step is the starting point for later work such as creating databases, creating tables, inserting records, and querying data. Continue with Create a database, Create a table, or Query a database.

Troubleshooting

“mysql” is not recognized as an internal or external command

This usually means that the current directory is not the MySQL bin directory, the bin directory is not in PATH, or the client tools were not installed.

  • Change to the installation bin directory with cd and try again.
  • Run mysql.exe using its full path.
  • Add the bin directory to PATH if you want to run mysql from any directory.
  • Confirm that the MySQL client tools were included in the installation.

Access denied for user

This message indicates an authentication or account-permission problem. The password or account name may be incorrect, the account may not be permitted to connect from the selected host, or its authentication configuration may differ from the assumed local root setup.

  • Check the account name and carefully re-enter the password.
  • Confirm that you are using the MySQL password, not the Windows administrator password.
  • For a remote server, check the account's permitted host and privileges.
  • If credentials are unavailable, follow the approved account-password recovery procedure rather than guessing passwords.

Cannot connect to MySQL server

The MySQL Server service may be stopped, or the host and port may be wrong. For remote connections, a firewall or other network configuration may also block access.

  • Confirm that the MySQL service is running in Windows Services or through the applicable service-management method.
  • Check the intended host name and port.
  • For remote connections, verify network reachability, firewall rules, and the server's remote-connection configuration.

The password prompt appears blank

This is normal. Type the password even though no characters appear, then press Enter to submit it.

The prompt changes instead of executing a query

A continuation prompt means that the client believes the statement is incomplete. The semicolon may be missing, or a quote, parenthesis, or comment may not be closed.

  • Complete the statement and end it with a semicolon.
  • Cancel unfinished input with the client clear command, commonly \c, when appropriate.

Exam-Relevant Notes

  • The MySQL client sends commands; the MySQL Server stores and manages data.
  • -u selects a MySQL user, while -p requests an interactive password.
  • Do not confuse the MySQL root password with a Windows administrator password.
  • localhost refers to the current computer, and 3306 is the common MySQL default port.
  • The mysql> prompt indicates a successful interactive client connection.
  • SQL statements normally require a terminating semicolon in the interactive client.