VMware ESXi and vSphere Cluster Management

Start the MySQL Command-Line Client on Windows

Learn how to open a Windows terminal, find the MySQL bin directory, connect with mysql, verify the connection, and troubleshoot common startup errors.

What the MySQL command-line client does

The mysql client is an interactive terminal program that connects to a running MySQL Server. A command-line interface (CLI) is a text-based environment where you enter commands instead of selecting actions in a graphical interface.

After connecting, you can enter SQL statements, inspect databases, create or modify database objects, and perform administrative tasks allowed by your MySQL account.

The client and server are different programs. The MySQL Server is the database service that stores data and accepts connections. The mysql client is the program that connects to that service. Starting the client does not start the server; the server must already be running.

Before you begin

  • MySQL Server and the client tools should be installed on Windows.
  • You need a MySQL account name and password, such as the root account created during setup.
  • The MySQL Server service must be running before a client can connect.
  • You should know how to open a Windows terminal and enter basic commands.

Open a Windows command shell

For the beginner-oriented procedure, use Command Prompt:

  1. Open the Windows Start menu.
  2. Type Command Prompt or cmd.
  3. Select Command Prompt.

You can also open the Run dialog with Windows key + R, enter cmd, and select OK.

Modern Windows installations also provide Windows Terminal and PowerShell. The commands in this lesson generally work in those environments too. The first prompt belongs to the Windows shell. After you start the MySQL client and connect successfully, the prompt changes to mysql>.

PromptEnvironmentWhat to enter
A prompt ending in >, often showing a folder pathWindows Command PromptShell commands such as cd and mysql
A prompt such as PS C:\Users\Name>PowerShellPowerShell commands or the MySQL startup command
mysql>MySQL clientSQL statements and client commands
->MySQL continuation promptComplete the unfinished SQL statement, or cancel it

Locate the MySQL client executable

Windows normally stores the mysql executable in the MySQL installation's bin directory. A bin directory is a folder containing executable programs.

Typical locations include the following, but the exact path depends on the installed version and the directory selected during installation:

C:\Program Files\MySQL\MySQL Server <version>\bin
C:\Program Files (x86)\MySQL\MySQL Server <version>\bin

Replace <version> with the directory name installed on your computer. You can inspect the MySQL folders under C:\Program Files\MySQL with File Explorer.

Navigate to the bin directory

At the Windows shell prompt, use cd to change folders. Quotation marks are useful because Program Files contains a space.

cd "C:\Program Files\MySQL\MySQL Server <version>\bin"

After changing directories, run the client from that folder. If the path does not exist, check the installed version and the installation location.

Optional: add the bin directory to PATH

The PATH environment variable is a Windows setting that tells a shell where to search for executable programs. Adding the MySQL bin directory to PATH lets you run mysql from any working directory.

  1. Open Windows search and look for environment variables.
  2. Open the option for editing the system environment variables, then open Environment Variables.
  3. Edit the appropriate Path variable and add the full MySQL bin directory, such as C:\Program Files\MySQL\MySQL Server <version>\bin.
  4. Save the changes and open a new Command Prompt or terminal window.
  5. Test the setting with mysql --version.

A new terminal is important because an already-open shell may still have the old PATH value.

Start a local MySQL client session

The basic command for connecting locally as a user named root is:

mysql -u root -p

The -u option specifies the MySQL account name. The -p option tells the client to request a password. Because no password value follows -p, the client displays an interactive password prompt.

When prompted, type the password configured for the account and press Enter:

Enter password:

Password characters are not displayed while you type. There may be no dots or asterisks; this is expected.

For routine work, use a separate non-root account with only the privileges it needs:

mysql -u <username> -p

The root account is a high-privilege administrative account. Protect it with a strong password and use it only when administrative privileges are necessary.

Recognize a successful connection

A successful login may display the MySQL client version, server version, connection information, and other introductory text. The most important sign is the interactive prompt:

mysql>

At this point, the client is connected and ready to send SQL statements to the server. Authentication is the process of proving your identity to the server with account credentials.

Run basic commands after connecting

SQL statements are entered at the mysql> prompt. They generally end with a semicolon, which tells the client to submit the statement.

Check the server version:

SELECT VERSION();

List databases visible to the connected account:

SHOW DATABASES;

The database list depends on the account's privileges. To select a database after connecting, use:

USE database_name;

You can also select a database when starting the client:

mysql -u <username> -p <database_name>

Exit the client cleanly with either command:

EXIT;
QUIT;

These are client commands accepted at the mysql> prompt. They return you to the Windows shell prompt.

Choose the connection host, port, and database

When the server is not running on the same machine, specify its host with -h. A host is a computer name or IP address where MySQL Server is running.

MySQL commonly uses TCP port 3306. If the server uses another port, specify it with uppercase -P:

mysql -h <host> -P <port> -u <username> -p

For example, a connection to a server named db.example on port 3307 could use:

mysql -h db.example -P 3307 -u <username> -p

Local connection behavior can vary by platform and configuration. If a local connection does not behave as expected, explicitly check the configured host and port, and try -h 127.0.0.1 when a TCP connection to the local server is intended.

OptionPurposeExample usage
-uSpecifies the MySQL account name-u appuser
-pRequests an interactive password prompt when no value is supplied-p
-hSpecifies the server host-h 127.0.0.1
-PSpecifies the TCP port; uppercase P means port-P 3307
Database name argumentSelects a database as part of startupmysql -u appuser -p sales

Handle passwords safely

Avoid placing a password directly in a command, such as -pMyPassword. Passwords in commands can be exposed through terminal history, screen recordings, logs, or process listings.

For interactive use, prefer -p without a password value:

mysql -u <username> -p

For automated connections, MySQL supports configuration-based credential approaches. Store such configuration in an appropriate protected file, restrict its Windows permissions so other users cannot read it, and follow your organization's credential-management rules. Do not commit passwords to source code or share them in scripts.

Use root only for tasks that require administrative privileges. For applications and everyday queries, a separate account with least-privilege permissions is safer.

Troubleshoot startup and connection errors

Symptom or messageLikely causeRecommended action
mysql is not recognized as an internal or external commandThe shell is not in the bin directory, PATH is missing the directory, or client tools were not installedUse cd to reach the actual bin directory, run mysql there, add that directory to PATH, or verify that the client tools are installed
Access denied for userWrong username or password, account host restrictions, or different authentication settingsCheck the account name and re-enter the password carefully. Confirm the host and account configuration. Use an authorized administrator to inspect privileges or reset credentials when necessary
Can't connect to MySQL serverThe server is stopped, or the host or port is wrongCheck the MySQL service in Windows Services or the installed server-management tools. Verify the host and port
Connection refusedNo server is listening at the selected host and port, or a firewall or network rule blocks accessStart or check the server, verify the port, and check firewall and remote-access settings
Unknown databaseThe named database does not exist or the name is misspelledConnect without the database name, run SHOW DATABASES;, and select an existing database or create one with appropriate privileges

Tell the Windows shell and MySQL prompts apart

Commands such as cd, mysql, and mysql --version belong at a Windows shell prompt. Statements such as SELECT, SHOW, and USE belong after mysql> appears.

If the prompt changes to ->, the client is waiting for the rest of an incomplete statement. A missing semicolon or closing quote is a common cause. Complete the statement correctly. If you want to discard the partially entered statement, enter \c and press Enter, then try again.

Complete first-connection example

  1. Open Command Prompt from the Start menu or Run dialog.
  2. Change to the actual MySQL bin directory, or open a new terminal after configuring PATH.
  3. Run mysql -u root -p, or use a non-root account for routine work.
  4. Enter the password at the hidden password prompt.
  5. Confirm that mysql> appears.
  6. Run SELECT VERSION(); and SHOW DATABASES;.
  7. Leave with EXIT;.

For a server on another host or a non-default port, include -h and uppercase -P in the startup command. For a specific database, append its name or use USE database_name; after connecting.