Answer to your first question: Each file contains info for the table
cars.frm
has the table structure
cars.MYD
has the table data
cars.MYI
has the table indexes
Given this layout, the cars table uses the storage engine MyISAM.
Answer to your second question: Yes, provided the following circumstances
- every table uses the storage engine MyISAM
- no INSERTs, UPDATEs, or DELETEs are running
- DB Connections using TCP/IP are disabled
To check to see if all the tables are MyISAM, run this query:
SELECT COUNT(1) TableCount,engine
FROM information_schema.tables
WHERE table_schema='db_test_1'
GROUP BY engine;
You should only see just MyISAM. If you see other storage engines, you cannot just copy.
If your root@localhost password is mypass
, here is all you need to to safely move all the tables regardless of storage engine:
# USERPASS="-uroot -pmypass"
# service mysql restart --skip-networking
# mysql ${USERPASS} -A -e"CREATE DATABASE db_test_2"
# mysqldump ${USERPASS} --routines --triggers db_test_1 | mysql ${USERPASS} -A -Ddb_test_2
# service mysql restart
If the data is huge, do this instead:
# USERPASS="-uroot -pmypass"
# service mysql restart --skip-networking
# mysql ${USERPASS} -A -e"CREATE DATABASE db_test_2"
# mysqldump ${USERPASS} --routines --triggers db_test_1 > /root/MyData.sql
# mysql ${USERPASS} -A -Ddb_test_2 < /root/MyData.sql
# service mysql restart
Give it a Try !!!
I created a script so that you switch the old DBName with the new DBName
Here is the script
DUMPFILE=junk.txt
DUMPFILENEW=junk.new
DBNAME_OLD=dbAccessData
DBNAME_NEW=rolando
LINE_CDB=`grep -n "^CREATE DATABASE" ${DUMPFILE} | sed 's/\`/ /g' | sed 's/:/ /g' | grep " ${DBNAME_OLD} " | awk '{print $1}'`
LINE_USE=`grep -n "^USE " ${DUMPFILE} | sed 's/\`/ /g' | sed 's/:/ /g' | grep " ${DBNAME_OLD} " | awk '{print $1}'`
(( LINES_IN_THE_MIDDLE = LINE_USE - LINE_CDB + 1 ))
LINES_IN_THE_DUMP=`wc -l < ${DUMPFILE}`
DUMP_SECTION1=${DUMPFILE}.Section1
DUMP_SECTION2=${DUMPFILE}.Section2
DUMP_SECTION2A=${DUMPFILE}.Section2a
DUMP_SECTION3=${DUMPFILE}.Section3
(( X = LINE_CDB - 1 ))
head -${X} ${DUMPFILE} > ${DUMP_SECTION1}
head -${LINE_USE} ${DUMPFILE} | tail -${LINES_IN_THE_MIDDLE} > ${DUMP_SECTION2}
(( X = LINES_IN_THE_DUMP - LINE_USE ))
tail -${X} ${DUMPFILE} > ${DUMP_SECTION3}
echo "sed 's/${DBNAME_OLD}/${DBNAME_NEW}/g' < ${DUMP_SECTION2} > ${DUMP_SECTION2A}" > change_dbname.sh
chmod +x change_dbname.sh
./change_dbname.sh
rm -f change_dbname.sh
cp ${DUMP_SECTION1} ${DUMPFILENEW}
cat ${DUMP_SECTION2A} >> ${DUMPFILENEW}
cat ${DUMP_SECTION3} >> ${DUMPFILENEW}
rm -f ${DUMP_SECTION1}
rm -f ${DUMP_SECTION2}
rm -f ${DUMP_SECTION2A}
rm -f ${DUMP_SECTION3}
cat ${DUMPFILENEW}
Here is the sample file (junk.txt, 30 lines)
-- MySQL dump 10.11
--
-- Host: localhost Database: dbAccessData
-- ------------------------------------------------------
-- Server version 5.0.51a-community-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Current Database: `dbAccessData`
--
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `dbAccessData` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `dbAccessData`;
--
-- Table structure for table `tblAccountLinks`
--
DROP TABLE IF EXISTS `tblAccountLinks`;
Here is the output
-- MySQL dump 10.11
--
-- Host: localhost Database: dbAccessData
-- ------------------------------------------------------
-- Server version 5.0.51a-community-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Current Database: `dbAccessData`
--
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `rolando` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `rolando`;
--
-- Table structure for table `tblAccountLinks`
--
DROP TABLE IF EXISTS `tblAccountLinks`;
Give it a Try !!!
Best Answer
The mysqldump utility can dump the following ways from a MySQL Instance:
--where
OptionYou cannot mysqldump two tables from two different schema. You must script the tables you want dumps one at a time.
Here is a script to dump every table from a MySQL Instance into separate files
In your case, you can create the /tmp/ListOfTables.txt file manually. In order to inject
use dbname
, just create the dump file with theuse dbname
as the first line. Then, append the output of mysqldump to it. Keep in mind that each table is described as dbname.tablename:Give it a Try !!!