0

This question already has an answer here:

Currently I am dumping my database (running under Linux Mint), from the command line, using the following:-

mysqldump -u[user] -p[password] MyDatabase > MyDatabase.sql

Now rather than dumping to a self-contained file I need to dump to a Project Folder so that I have a .sql file per table. However despite trawling the web and a couple of MySQL books I have been unable to find an option for this. Can anyone help?

marked as duplicate by RolandoMySQLDBA mysql Dec 23 '15 at 19:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Do it in 2 steps...

Write a SELECT against information_schema.TABLES to generate one mysqldump statement per table. Send the output of that to a file; then execute that file. (Also, give the file execute permission).

0

To dump each table in its own sql file, you would need the list of the tables,

#!/bin/bash
// define your database name here
mydbname="MyDatabase"

// Select the list of tables into an array 'mytables'
// Note repalce the user and password in the mysql statement before execution.
mytables=$(mysql -uroot -se "select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='${mydbname}' and TABLE_TYPE='BASE TABLE'")

// Now loop through each table and dump into its own file.
for table in $mytables
do
        echo "Table : ${table}";
        mysqldump -uroot ${mydbname}  ${table} > ${mydbname}.${table}.sql
done

Not the answer you're looking for? Browse other questions tagged or ask your own question.