英文:
I have installed MySQL and have added the directory to my PATH but it still isnt working
问题
我从**https://dev.mysql.com/downloads/installer/**下载了MySQL安装程序。然后,我通过安装程序设置了它。完成后,我尝试在Windows PowerShell和CMD中测试命令,但两者都不起作用。
我在网上尽力查找问题所在,但没有什么真正起作用。我找到一篇帖子说要将MySQL路径添加到主系统路径中,于是我这样做了。我使用的命令是:
SET PATH=%PATH%;C:\Program Files\MySQL\MySQL Server 8.0\bin
我还手动编辑了环境变量并检查了一切。然而,一个非常奇怪的事情是,当我在cmd中运行该命令时,mysql --version
命令可以正常工作!但当我在Powershell中运行相同的命令时,它就不行了,当我关闭Windows Terminal并重新打开它时,在cmd中这个命令再也不起作用!我真的不知道发生了什么。在PowerShell中,我收到的错误消息是:
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.
在CMD中,我收到的错误消息是:
C:\Users\User>mysql --version
'mysql' is not recognized as an internal or external command,
operable program or batch file.
如果有人能帮助我,那将是太棒了,谢谢。
英文:
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.
答案1
得分: 0
将路径添加到PATH的方式只是临时的。它只在终端打开的时候有效,当终端关闭时,路径的更改也会被清除。请使用setx
而不是set
来使其永久生效,或者使用Windows设置界面进行更改。要进行后者,打开设置对话框,然后在搜索框中键入"Environment",然后选择更改系统环境变量的选项。当系统属性对话框出现时,点击右下角的"环境变量"按钮。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论