1

So I downloaded the MySQL installer from https://dev.mysql.com/downloads/installer/. I then went through the process of setting it up via the installer etc. After this was complete, I went to test the command in both Windows PowerShell and CMD, but neither worked.

I looked everywhere I could online to find out what the issue was, but nothing really worked. I found a post that said to add the MySQL path to the main system PATH and so I did. The command I used was:

SET PATH=%PATH%;C:\Program Files\MySQL\MySQL Server 8.0\bin

I also manually edited my environment variables and checked everything there. HOWEVER, a really weird thing is that when I run that command in cmd the mysql --version command WORKS! When I run the same command in Powershell it doesn't, and when I close Windows Terminal and re-open it, the command no longer works in cmd! I really have no idea whats going on. The error message I receive in PowerShell is:

PS C:\Users\User> mysql --version
mysql: The term 'mysql' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

And the error message I receive in CMD is:

C:\Users\User>mysql --version
'mysql' is not recognized as an internal or external command,
operable program or batch file.

If anyone could give me a hand, that'd be amazing, thanks.

mklement0
  • 382,024
  • 64
  • 607
  • 775
LeviLM
  • 13
  • 2

1 Answers1

0

Adding to the PATH the way you did is only temporary. It lasts as long as the terminal is open, and when the terminal is gone, so is the change to the path. Use setx instead of set to make it permanent, or make the change using the UI in Windows settings. To do the latter, open the Settings dialog and type Environment into the search box, and then choose the option to change the system environmental variables. When the System Properties dialog appears, click the Environmental variables button at the lower right.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • 1
    While using `setx.exe` to persistently modify the `Path` environment variable _may_ have no (immediate) ill effects, it _can_: `setx.exe` has a hard 1024-character limit, and invariably replaces the original `REG_EXPAND_SZ` value with a `REG_SZ` value, which means that basing entries on _other_ environment variables no longer works. Additionally, you're _duplicating_ entries by basing your new value on `$env:Path`, which is a _composite_ of the system-level and the user-level definition. See [this answer](https://stackoverflow.com/a/69239861/45375). – mklement0 Feb 19 '23 at 00:17