Gokhan Kurt
Gokhan Kurt

Reputation: 8277

Mysql import command working when running on cmd but not when passing arguments directly

As I follow from the documentation, The import command in its most basic form is:

mysql.exe < example.sql

It works when I run it from the command line in Windows. But it doesn't work when I start the process mysql.exe with < example.sql parameters. For example, creating a shortcut and setting its path to mysql.exe < example.sql doesn't work and it only prints the help info for mysql.exe.

As a side note, I first noticed this problem when trying to run the following C# code:

new Process
        {
            StartInfo = new ProcessStartInfo
            {
                FileName = "mysql.exe",
                Arguments = "< example.sql",
            }
        }.Start();

Upvotes: 3

Views: 183

Answers (2)

aschipfl
aschipfl

Reputation: 34899

The part < example.sql does not contitute parameters for mysql.exe; the < character denotes a redirection operator, so the content of file example.sql is redirected into mysql.exe.

I guess you have to change the file name to cmd.exe and the arguments to /C "mysql.exe < example.sql". Consider to specify full absolute paths to all of the files.

Upvotes: 2

Wouter
Wouter

Reputation: 1353

I don't work in windows but I assume you best fill in the full path + database hostname information:

C:\mysql\directory\bin\mysql -h {hostname} -u {username} -p {databasename} < example.sql

Upvotes: 0

Related Questions