I am trying to execute MySQL query which gives me the output as CSV file to the specified directory.
func executeCommand(){
cmd := exec.Command("/usr/local/mysql/bin/mysql", "-e", "-hlocalhost", "-P3131", "-uroot", "-pmyPassword", "dbName", "> /path/to/output/folder/fileName.csv")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err = cmd.Run()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
}
fmt.Println("Result: " + out.String())
}
I am getting the following error:
exit status 1: mysql: [Warning] Using a password on the command line interface can be insecure.
When I removed the output directory path then there is no error. But I need my output generated file to the specified directory.
I also tried replacing >
with source
but no luck.
Also, when I'm running the same on Terminal it is working as intended but I am failing to replicate the same through Go.
/usr/local/mysql/bin/mysql -e "select * from tableName" -u root -p -h localhost -P 3131 dbName > /path/to/output/folder/fileName.csv
I tried searching on SO but couldn't find anything relevant. Any help would be appreciated.