Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-06-13
4
Medium Priority
?
1,834 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 79

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 1000 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

721 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