How to import/load/run mysql file using golang?

I’m trying to run/load sql file into mysql database using this golang statement but this is not working:

exec.Command("mysql", "-u", "{username}", "-p{db password}", "{db name}", "<", file abs path )

But when i use following command in windows command prompt it’s working perfect.

mysql -u {username} -p{db password} {db name} < {file abs path}

So what is the problem?

The redirection < is a shell operation, but you’re not running a shell. You can open the file and pipe it yourself (see the Stdin thing on exec.Command), or you can write it as a shell script instead.

Yes you’re right. Somebody asked me in stackoverflow with a nice way.

Answer link:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.