Solved

MySQL windows batch file need to escape backslashes in %CD% or convert them to forward slashes

Posted on 2008-06-13
4
1,828 Views
Last Modified: 2010-04-21
Hello,
I have a Windows batch file containing the following command:

mysql -uuser -ppassword thedatabase -e
 "select * into outfile '%CD%\\thetable.csv' FIELDS TERMINATED BY ',' OPTIONALLY
 ENCLOSED BY '\"' ESCAPED BY '' LINES TERMINATED BY '\r\n' from thetable;"

and when it is run I get the error
ERROR 1 (HY000) at line 1: Can't create/write to file 'C:WorkDatabase\thetable.csv' (Errcode: 2)

The current directory is C:\Work\Database and what's happening is MySQL is interpreting the backslashes as an escape character. The solution is to convert %CD% to double the backslashes or substitute a forward slash for them.
0
Comment
Question by:pdegregorio
  • 2
4 Comments
 
LVL 77

Expert Comment

by:arnold
ID: 21782719
Replace %CD% with c:\\Work\\database is the easiest.

Define the CD variable as c:\\Work\\database at the beginning of the batch.
0
 
LVL 5

Accepted Solution

by:
Alex-w474 earned 250 total points
ID: 21782762
This will help: BAT file tips - http://www.alexatnet.com/node/22
SET FOLDER=%CD%
ECHO %FOLDER:\=\\%

Open in new window

0
 

Author Comment

by:pdegregorio
ID: 21782841
Using Alex-w474 suggestion the following works:

mysql -uuser -ppassword thedatabase -e
 "select * into outfile '%CD:\=\\%\\thetable.csv' FIELDS TERMINATED BY ',' OPTIONALLY
 ENCLOSED BY '\"' ESCAPED BY '' LINES TERMINATED BY '\r\n' from thetable;"

Thank you!
0
 

Author Closing Comment

by:pdegregorio
ID: 31467077
Very nice, elegant solution. Thanks for the speedy reply.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question