dongsha1544 2018-03-15 14:48
浏览 254

如何使用Golang导入/加载/运行mysql文件?

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?

  • 写回答

3条回答 默认 最新

  • dongliyi967823 2018-03-15 14:57
    关注

    Go's exec.Command runs the first argument as a program with the rest of the arguments as parameters. The '<' is interpreted as a literal argument.

    e.g. exec.Command("cat", "<", "abc") is the following command in bash: cat \< abc.

    To do what you want you have got two options.

    The problem with the bash version is that is not portable between different operating systems. It won't work on Windows.

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)