D
D
DILYAR2018-03-03 22:02:22
linux
DILYAR, 2018-03-03 22:02:22

How to make a copy of all mysql databases in separate files?

Hello. Tell me how to make copies of all databases in separate files with the names of these databases. How it's done through "Export" in phpmyadmin
On the Internet I found only how to make a common database or separately. I would like to somehow separately, but at the same time everything is in automatic mode

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AVKor, 2018-03-03
@AVKor

In automatic mode, this is done by writing a bash script. Get a list of databases -> cycle through the entire list and make a dump for each of them into a separate file with the appropriate name.

D
Daniel, 2018-03-03
@daniil14056

I don't quite understand what it means

On the Internet I found only how to make a common database or separately

and
I would like to do it separately

But in general it is quite simple (password immediately after -p)
in the console of mysql itself: mysql> LOCK TABLES base_name.table_name READ;
in the cmd console: C:\MySql\bin>mysqldump -uUser -pPassword and bd_name table_name > file_table.sql
then unlock in mysql mysql> UNBLOCK TABLES
Well, you can loop through the tables you need, pass a list of their names, and go through each name, creating a sql file of the same name for each table.
You can simply create a file with a list of tables line by line, then read it and loop through them, you can think in a batch file, but I don’t know the syntax there.
// на JAVE как то-так, думаю вполне понятно
public class Export{
public static void main(String []arg){
String tables[];
if(args.length==0)
  tables =new Array(){"table1","table2","table3"};
else{
    tables =new String[args.length];
     System.copyarray(tables,0,args,0,args.length);
}
 for( table : tables){
      Process proc = Runtime.getRuntime().exec("cmd  C:\MySql\bin>mysqldump -uПользователь -pПароль и bd_name "+table+" > file_"+table+".sql");
   }
}}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question