Search code examples
cmdcommandmysqlexecutebasic

Invoking mysqldump from script without password prompt


I need to execute a cmd command in Visual Basic. It's not difficult but i need to give a argument while the external Programm runs.

F:\mysql-5.7.13-winx64\bin\mysqldump.exe -h <ip> -u <user> -p <database> > abcd.sql

But after that is executed, the programm will ask for a password. So how can i do that?

Greetings, Dominic


Solution

  • You can provide a password at command line (not secure):

    mysqldump.exe -h <ip> -u <user> --password="my_password" <database> > abcd.sql
    

    You can also use Mysql options file. Create my.cnf with credentials details:

    [mysqldump]
    host="my_host"
    user="my_user"
    password="my_password"
    

    And provide it to mysqldump

    mysqldump.exe <database> --defaults-extra-file=my.cnf > abcd.sql