I am adding this string C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 & MySQL Utilities 1.5\
to my windows 10 environmental variable PATH. This caused problem to the PATH. I believe the root cause is the character &
in the string. How can I add the string successfully to the windows PATH?
Asked
Active
Viewed 964 times
4

guagay_wk
- 26,337
- 54
- 186
- 295
-
1I've just tried this out with a directory that includes an ampersand, and it works perfectly well (without quote marks) for me. I suspect the problem is not with the ampersand in the PATH but with the way in which you're adding it. – Harry Johnston Dec 07 '15 at 00:50
-
Thanks. Strange that adding quotations helped solve my problem. – guagay_wk Dec 07 '15 at 00:51
-
1Without more information (about how you're adding the string to PATH, and what you're using it for) I can't really venture any further guess. And I'm on Windows 7 so I guess Windows 10 might behave differently. But so long as you've got it working that's all that really matters right now. – Harry Johnston Dec 07 '15 at 00:58
2 Answers
5
Try escaping the ampersand (&) with a carrot (^).
C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 ^& MySQL Utilities 1.5

cwahls
- 743
- 7
- 22
-
Thanks. Upvoted. Would it be a good idea to wrap the entire PATH variable with quotations? – guagay_wk Dec 07 '15 at 00:32
-
1
-
But would it be a good practice to wrap every directory with quotations? – guagay_wk Dec 07 '15 at 00:40
-
1No. Quotations are not (ordinarily) either necessary nor recommended. – Harry Johnston Dec 07 '15 at 00:42
-
@Harry Johnston, may I ask why? wouldn't that practice have prevented the problem that I encountered in this question? – guagay_wk Dec 07 '15 at 00:43
-
1Yes, you can wrap every one. For ones without spaces, they are not needed. – cwahls Dec 07 '15 at 00:43
-
1Directories with spaces don't need quotes either. I don't know for certain whether including quotes will break stuff (though I have a vague recollection that it does) but it is not standard practice. – Harry Johnston Dec 07 '15 at 00:46
-
Thanks. Based on your advice, I guess it is safer practice to wrap quotes only when necessary. – guagay_wk Dec 07 '15 at 00:47
-
Running the vcvars32.bat reported that it cannot find the MySQL external/internal program at a line like `set PATH=[...];%PATH%`. I added quotes, and then the same batch file produced the same error for a different line, something like `set PATH="[...];%PATH%"` (note the quotes). So surrounding it with quotes does not solve every case. The only solution I see is to rename the directory, or remove it from PATH. – Adam L. S. Apr 03 '16 at 19:21
-
-
Looks as if the quotation marks may indeed be harmless: https://blogs.msdn.microsoft.com/oldnewthing/20060929-06/?p=29533 – Harry Johnston Apr 27 '16 at 02:17
-
If i use ^ character before & then & will be skipped. In Normally below path to be set in PATH Variable C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 & MySQL Utilities 1.5 If i use "^" before it then & will be ignored then path will be set like below. C:\Program Files (x86)\MySQL\MySQL Fabric 1.5 MySQL Utilities 1.5 It may affect the some MYSQL Functionalities due to wrong class path. – Mister X Sep 14 '16 at 11:52
2
I had the same problem as you on windows 7 after installing MySQL 5.7.11.
The issue is that the MySQL installer adds two paths containing & to the PATH system variable without surrounding them by quotation marks.
This may cause all sorts of trouble to other BATCH files. For instance a simple:
echo %PATH%
from the command line would actually execute the mysql client because MySQL appears after the & which Windows sees as way to combine separate commands. This caused other scripts like Python virtual environment activate to misbehave on my machine.
Surrounding the two MySQL paths in the PATH environment system variable permanently fixes the issue. So it looks like a bug in MySQL installer.

user3748764
- 346
- 2
- 11
-
Not really a bug. Unwise, perhaps, but not a bug. (The "bug" is in the batch file, which fails to take the possibility of special characters in the PATH into consideration.) – Harry Johnston Mar 24 '16 at 20:51
-
No, it's a bug. They should quote the route or escape the ampersand. It is really annoying and it's the source of PATH anomalies. If you have other routes on the PATH after the broken mysqls ones, the programs on those routes won't be detected when you try to run them. – Esteban Filardi Apr 26 '16 at 21:08
-
@EstebanFilardi: I've just tried this out (a PATH string containing an unquoted ampersand in the first directory) and it works perfectly well for me. But they should fix it anyway, preferably by renaming the directory; the fact that it is technically a legal character does not make it a good idea. – Harry Johnston Apr 27 '16 at 02:20
-
Yes, you are right. I wrote anomalies, because weird things happens when you have the PATH variable "corrupted" like that. It doesn't happen with normal the command line, but it does with the VS Command prompt developer tools (I've tested it). – Esteban Filardi Apr 27 '16 at 02:37