-4

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?

Rup
  • 33,765
  • 9
  • 83
  • 112
  • There will be a password. Do you have an application that uses this database successfully? You can probably find a password, though maybe not the root password, in that app's config. Worst case you can stop mysql and restart it `--skip-grant-tables` then change the password to something you do know. – Rup Jul 01 '19 at 08:45
  • @rup But I didn't setup any password on mysql. So what password I would have to change – Puneet Jindal Jul 01 '19 at 09:14
  • It might either be [empty (just hit return) or 'password'](https://stackoverflow.com/a/5818385/243245). But whether you know it or not [you can follow these steps to change it](https://askubuntu.com/a/766908/24979). – Rup Jul 01 '19 at 09:17
  • @rup I have checked in user account see in the given screen shot: https://nimb.ws/suN974 there is no password in the user account – Puneet Jindal Jul 01 '19 at 09:22
  • Sorry, I don't know my mysql behaves with no passwords set. I've put your screenshot in the question so hopefully someone else will recognise what's happening here. – Rup Jul 01 '19 at 09:50
  • @rup okay thankyou for the links. Anyone other will give me the solution for this? – Puneet Jindal Jul 01 '19 at 10:02
  • Why is this question tagged with phpmyadmin? – Dharman Jul 01 '19 at 18:07

2 Answers2

0

It is prompting you to specify a password because you asked it to.

First skip -p in your command.

Use

--skip-password

To explicitly specify that there is no password and that mysqldump should not prompt for one.

0

I have 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.

Abhinav
  • 83
  • 1
  • 10
Puneet
  • 615
  • 2
  • 7
  • 17