Kellen Stuart
Kellen Stuart

Reputation: 8913

How to escape "<"?

How do you escape this command in PowerShell?

mysql -uuser -ppass -hlocalhost -Ddb < .\someSqlFile.sql

I need to escape the <.

Contents of someSqlFile.sql:

SELECT * FROM some_table 
INTO OUTFILE 'C:/tmp/output.csv' 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"' 
LINES TERMINATED BY '\n';

Upvotes: 0

Views: 121

Answers (2)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200323

PowerShell doesn't support input redirection (<). Either execute the command with CMD (from PowerShell):

cmd /c mysql -uuser -ppass -hlocalhost -Ddb '<' .\someSqlFile.sql

or pipe the content of the file into the command:

Get-Content .\someSqlFile.sql | & mysql -uuser -ppass -hlocalhost -Ddb

Upvotes: 4

Bill Karwin
Bill Karwin

Reputation: 562488

An alternative to using input redirection is to use the source command in the mysql client.

mysql -uuser -ppass -hlocalhost -Ddb -e "source ./someSqlFile.sql"

I am not a PS user, so I can't offer the right syntax for the last argument. It's supposed to be one argument, but it contains a space. I searched a few other sites looking for a concise technique to use a single argument including spaces in PS, but it's not that easy I guess. :-)

To solve your problem of exporting one table in CSV format another way, you might like to use mysqldump:

mysqldump -uuser -ppass -hlocalhost --tab=C:/tmp db some_table

This outputs a file some_table.sql and a file some_table.txt which are the DDL and the data for that table, respectively.

Upvotes: 0

Related Questions