Dump command for mysql

Hi there!

Anyone knows how can I generate a dump of a mysql database (in xojo), to use it as backup? I can’t find any info about this…

Thanks!

probably easiest would be to run a command line backup from a shell in xojo.

http://www.liquidweb.com/kb/how-to-back-up-mysql-databases-from-the-command-line/

mysql has a separate program for creating dumps
http://dev.mysql.com/doc/refman/5.0/en/backup-methods.html

you’d need to use a shell to run it

OR you write your own dump (which I’d not suggest)

[quote=139255:@Rich Hatfield]probably easiest would be to run a command line backup from a shell in xojo.

http://www.liquidweb.com/kb/how-to-back-up-mysql-databases-from-the-command-line/[/quote]
But, will the command line works from a client (my data is on a server)?

yes. it connects to the dbase like the client does, then will dump the database out to standard out or redirected to a file.

Your app would have to run on the server where mySQL is to do the dump & have the correct permissions/privileges

As long as it does you can use the mysql command line app

I created a little client-side “dump” sql file project on github

https://github.com/Budjhete/xojo.desktop.mysql.backup

don’t be shy to request a git push on my project :wink:

[quote=245769:@Etienne Pilon]I created a little client-side “dump” sql file project on github

https://github.com/Budjhete/xojo.desktop.mysql.backup

don’t be shy to request a git push on my project ;-)[/quote]
Interesting… I’ll take a look in the next days.
Many thanks!

Interesting code, thanks a lot for that, i was looking for something like that and i was afraid to use those command line tools.

Is there a way for restore as well ? i see that it creates a backup in Documents folder. If i need to restore that sql , any ideas ?

Thanks in advance.

I’m invoking mysqldump from a shell, and says: “command not found”, nevertheless If I run mysqldump on a Terminal on my Mac, in runs without problem.

Do I missing something?

  Dim f as FolderItem = SpecialFolder.Desktop
  Dim comando As String = "mysqldump facturacion > " + f.ShellPath + "/facturacion.sql"

  Dim sh As New Shell
  sh.Execute(comando)
  Msgbox sh.Result

You need to pass the full path to the mysqldump binary when you use a Xojo shell.

It doesn’t have the same path environment variables as Terminal.

[quote=341101:@Jared Feder]You need to pass the full path to the mysqldump binary when you use a Xojo shell.

It doesn’t have the same path environment variables as Terminal.[/quote]
Yes, you are right!!!, Now I can invoke it correctly, but so I have another Issue.

When I use without password, it says that can’t access without password, but never prompt for it.
Then I put the password in the command line and also It can access, it says:

mysqldump: [Warning] Using a password on the command line interface can be insecure.
mysqldump: Got error: 1045: Access denied for user ‘root’@‘localhost’ (using password: YES) when trying to connect

Thats my code

  Dim f as FolderItem = SpecialFolder.Desktop
  Dim comando As String = "/usr/local/mysql/bin/mysqldump -u root -password=mypassword facturacion > " + f.ShellPath + "/facturacion.sql"
  Dim sh As New Shell
  
  sh.Execute(comando)
  Msgbox sh.Result

[quote=341105:@Gerardo García]Yes, you are right!!!, Now I can invoke it correctly, but so I have another Issue.

When I use without password, it says that can’t access without password, but never prompt for it.
Then I put the password in the command line and also It can access, it says:

mysqldump: [Warning] Using a password on the command line interface can be insecure.
mysqldump: Got error: 1045: Access denied for user ‘root’@‘localhost’ (using password: YES) when trying to connect

Thats my code

[code]
Dim f as FolderItem = SpecialFolder.Desktop
Dim comando As String = "/usr/local/mysql/bin/mysqldump -u root -password=mypassword facturacion > " + f.ShellPath + “/facturacion.sql”
Dim sh As New Shell

sh.Execute(comando)
Msgbox sh.Result
[/code][/quote]

Ok, I found my error:
I’m using: -password=mypassword, instead of –password=mypassword
Then It makes the Backup successfully, It shows the Security Password Message about using Password’s in shell, but It makes the password, without problem. :smiley: :smiley: :smiley: :smiley:

Now I’m using #if Target in order to have this path in case of macOS: /usr/local/mysql/bin/mysqldump
And for Windows: /ProgramFiles/mySQL/MySQL Server 5.7/bin

But now as you can see, apparently I have another issue,what about if the mysql is upgraded?, the name of folder will change?

I’m Trying to execute “mysql -v” in order to know the mySQL version and add it to the Path string,

Regards