c# - Can't write to process's input -



i'm trying make c# function make database dump mysql server. , may know, mysql asks password this: enter image description here

so here's did:

public static bool backupdatabase(string filename) {     try     {         string mysqldumpdir = @"c:\program files\mysql\mysql server 5.7\bin\mysqldump.exe";         string user = "root";         string password = "root";         string databases= "hrsmarttest7";         processstartinfo startinfo = new processstartinfo         {             filename = mysqldumpdir,             redirectstandardinput = true,             arguments = string.format("--user {0} --password --databases {1} --result-file=\"{2}\"", user, databases, filename),             useshellexecute = false,             createnowindow = true         };         var mysqldump = new process { startinfo = startinfo, enableraisingevents = true };         mysqldump.start();         system.threading.thread.sleep(3000);         mysqldump.standardinput.autoflush = true;         mysqldump.standardinput.write(password+"\n"); // doesn't job !!!         mysqldump.waitforexit();         mysqldump.close();         return true;     }     catch (exception e)     {         //recordexception(e);         return false;     } } 

when execute function, process starts , waits user write password mysqldump.standardinput.write doesn't write , have kill process end program.

please help.

you can add .my.cnf file

[mysqldump] user=root password=root 

it safer passing password on command line and/or storing in source code. however, file client's machine should create read-only user backing databases rather using root. backup user needs following permissions:

grant lock tables, select on *.* 'backupuser'@'%' identified 'password'; 

see blog benjamin cane further details:


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -