How can I access MySQL from the command line with XAMPP in Windows?

On my windows computer, I have installed the xampp with PHP version 7.4.30 and MariaDB 10.4.25. I can access localhost/phpmyadmin, but when I try to access through the command line (cmd), it shows the following error.

'mysql' is not recognized as an internal or external command, 
operable program or batch file.

How can I access MySQL on a Windows computer?

All you need to do is go to your MySQL bin folder. If you didn’t change the installation path during install the xampp, then it should be in c:\xampp\mysql\bin. From there, your MySQL command should work as expected.

1. Open your command prompt (cmd), then cd to the bin directory.

cd c:\xampp\mysql\bin

2. Try “mysql” or “mysql.exe”

mysql -u root --password
// or
mysql.exe -u root --password

Hope that solves your problem.

Another solution could be setting up windows Environment Variables.

  1. Go to Control Panel > System > Advanced system settings.
  2. Click on the ‘Advanced’ tab.
  3. Or just search ‘Environment Variables’.
  4. Click on ‘Environment Variables’.
  5. Under System Variables, edit the ‘Path’ Variable
  6. Append the path to the end of the existing ‘Variable value’.
%systemDrive%\xampp\mysql\bin\ 

or, maybe

c:\xampp\mysql\bin\ 

Now, open a new command prompt to make this change take effect (already opened cmd won’t work).