How to Find the Path to the MySQL Installation Directory on Windows and Add it to PATH Environment Variable

The main console utilities for working with MySQL are located in the directory where MySQL Server is installed. However, after installing MySQL Server, it is often difficult to find this directory. The best way is to add this path to your PATH environment variable, and then you can use MySQL and mysqldump utilities directly.

How to find the MySQL installation directory on Windows via UI

MySQL for Windows is service-based. To find the MySQL installation directory, look at the executable file specified in the MySQL Service. To view the value, follow the instructions below:

  1. Press Win+R
  2. Type services.msc
  3. Find MySQL service in the list, it is usually named as MySQL [version number], for example, MySQL 80
  4. Click on it with the right mouse button and select “Properties”
  5. The path to the mysqld.exe file can be seen in the “Path to executable” field

How to Find MySQL Installation Directory Using the Command Line

All actions that you do in the Windows user interface can be performed using a PowerShell script.

The following long PowerShell command shows the path to the MySQL installation directory:

$service_path = Get-WmiObject win32_service | ?{$_.Name -like '*mysql*'} | Select-Object -Property PathName -First 1 | Format-Table -HideTableHeaders | Out-String; $service_path.split('"')| Where-Object {$_ -like "*mysqld.exe*"}  | %{$_.replace('mysqld.exe','').trim() }

 

How to Add the Path to the MySQL Server to Environment Variables

  1. Press Win+S to open a search box on your computer.
  2. Start typing “Environment” in the Windows search text box and select the “Edit the system environment variables” option in the “Best match” list.
  3. In the “System Properties” window that opens, you will find tabs such as “Computer Name,” “Hardware” and other additional properties. Go to the “Advanced” tab and click the “Environment Variables” button at the bottom. On this tab, you can also set the parameters “Performance,” “User Profiles” and “Startup and Recovery.”
  4. The “Environment Variables” window will open. It is divided into two fields with user variables and system variables, where all variables and their values are displayed. Find “Path” variables in the “System variables” field as shown in the screenshot above.
  5. Double click on the “Path” variable to open a list with all Path variables, in which Path variables can be edited, added, or removed.
  6. Press the “New” button and enter a new path, for example, “C:\Program Files\MySQL\MySQL Server 8.0\bin\”, in a new editable line.
  7. Click OK to save the new PATH variable. However, for these changes to affect your command prompt window, you need to open it again.

1 thought on “How to Find the Path to the MySQL Installation Directory on Windows and Add it to PATH Environment Variable

Leave a Reply

Your email address will not be published. Required fields are marked *