dow57588 2019-07-01 08:33
浏览 909
已采纳

如何解决mysqldump错误:1044:选择数据库时,“拒绝用户'@'localhost'访问数据库'db_name'”

I use mysqldump command to dump the some information from the sql tables. To do this I read about mysqldump. Then for a test I made a direct command which will run able in the terminal shell. That command were successfully produces the result which I needed. Then after that I have to implemented the command in my application code. My application is in the golang. Using exec.Command() I will able to run that command. But there is a run time error while the command will executed. The error I'm facing in terminal is:

exit status 2: mysqldump: Got error: 1044: "Access denied for user ''@'localhost' to database 'db_name'" when selecting the database

Command which I used:

direct command which produce success result sudo mysqldump -h 127.0.0.1 --no-create-info db_name table_name --where='id=1121' > /path/of/file/php1_dump.sql

code I'm using in golang:

cmd := exec.Command("sh", "-c", "mysqldump -h 127.0.0.1 --no-create-info db_name table_name --where='id=1121' > /home/iron/go/php1_dump.sql")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr

err := cmd.Run() // give the above error I mentioned

if err != nil {
    fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
    fmt.Println("errrrrrrrrrrrrrrrrrrrr", err) // exit status 2
}
fmt.Println("Result: " + out.String())

I also tried the below commands:

sudo mysqldump -h 127.0.0.1 -u root -p --no-create-info bk_admin wp_merchants --where='id=1121' > /home/iron/go/php1_dump.sql

The above command ask to enter the password. But I didn't setup any password of phpmysqladmin:

User accounts overview page: all accounts have Password: No

Please tell me that where I'm doing this wrong?

  • 写回答

2条回答 默认 最新

  • duanchazhou6779 2019-07-02 03:41
    关注

    I were also faced this same problem. I think you will have to make a new user in your phpmyadmin -> users_account with a valid username and password. Also check all the privileges. Hope it will help you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了