Immediate Fix: Run via Standard Command Prompt
The most common reason the MySQL Command Line Client closes instantly is an authentication error. When you use the default shortcut, the window terminates the second it encounters an error, giving you no time to read the message.
To fix this immediately, do not use the MySQL shortcut. Instead, open a standard Command Prompt (cmd.exe) and navigate to your MySQL bin folder or use the following command:
mysql -u root -p
By running it this way, if the connection fails, the window will stay open. This allows you to see the specific error code, such as “Access denied” or “Can’t connect to MySQL server.”
Technical Explanation: Why the Black Screen Disappears
When you launch the “MySQL Command Line Client” from the Start menu, Windows executes a command that opens a console window specifically for that process. If the MySQL service (mysqld) is not running or if your password has expired, the process exits.
In Windows, when a process launched directly from a shortcut finishes (or crashes), the hosting terminal window closes automatically. This is why you see a brief “black screen” flash before it disappears.

Alternative Methods to Resolve the Issue
Method 1: Verify the MySQL Service is Running
If the MySQL service is stopped, the command line client cannot connect. Use the following steps to ensure the database engine is active:
- Press
Win + R, type services.msc, and hit Enter. - Locate MySQL (e.g., MySQL80) in the list.
- Right-click it and select Start if it is not already running.
Method 2: Common Error Codes Table
Use this table to identify why your connection might be failing based on the error message you see in the manual command prompt:
| Error Code | Meaning | Likely Fix |
|---|---|---|
| ERROR 1045 (28000) | Access denied for user | Check your password or reset the root user. |
| ERROR 2003 (HY000) | Can’t connect to MySQL server | Start the MySQL service in services.msc. |
| Variable ‘password’ is not defined | Syntax error | Ensure you use -p and enter the password when prompted. |
Method 3: Check Environment Variables
To run MySQL from any command prompt without navigating to the installation folder, you must add the MySQL bin path to your System Environment Variables.
# Example path to add to PATH variable:
C:\Program Files\MySQL\MySQL Server 8.0\bin
Once added, you can simply type mysql -u root -p in any fresh terminal window to access your database without the window closing unexpectedly.