Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

Why does the Windows mysql client requrie forward slashes when using INTO OUTFILE via the command prompt?

If I want to save selected data from a table to an output file, I have to save it to the approved directory specified by the secure_file_priv variable. However, even If change the output file path to the approved directory, it still doesn't work, producing the following error- the same error I got before I started using the secure_file_priv specified directory:

mysql> SELECT * FROM customers
-> INTO OUTFILE " C:ProgramDataMySQLMySQL Server 5.7Uploadsoutput.txt";
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

Which had me nonplussed, since I had changed the directory to the appropriate directory specified by secure_file_priv, I shouldn't be getting that error any longer. Hoewever, when I changed the backslashes in the path to forward slashes, the query worked, and created the file.

mysql> SELECT * FROM customers
-> INTO OUTFILE "/ProgramData/MySQL/MySQL Server 5.7/Uploads/output.txt";
Query OK, 2 rows affected (0.00 sec)

Why is that? I did all of this on Windows via the command line, so I don't see why I had to use forward slashes, almost as if I was working on a *nix system.

question from:https://stackoverflow.com/questions/65867324/why-does-the-windows-mysql-client-requrie-forward-slashes-when-using-into-outfil

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Because the backslash is a metacharacter in strings.

For example, is a newline, not two characters.

https://dev.mysql.com/doc/refman/8.0/en/string-literals.html documents all the backslash-sequences that have special meaning. That page also says:

For all other escape sequences, backslash is ignored. That is, the escaped character is interpreted as if it was not escaped. For example, x is just x.

So your string:

C:ProgramDataMySQLMySQL Server 5.7Uploadsoutput.txt

Is interpreted as the following, because none of the backslashes form valid escape sequences:

C:ProgramDataMySQLMySQL Server 5.7Uploadsoutput.txt

This is why I gave up on Microsoft a long time ago. They knew better. The backslash was an escape character in programming languages long before Microsoft first used it as a directory separator. They shouldn't have done that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...