Julien Julien - 19 days ago 7
MySQL Question

mysqldump generating empty tables

I am trying to restore a database backup to a new database, and it didn't add tables. I use MySQL 5.5.17 for MacOSX 10.6 (Lion).

I saved the database called "mydatabase" with the following command:

/usr/local/mysql/bin/mysqldump --add-drop-table --user=root --password=mypass mydatabase > /Users/Me/Desktop/backup.sql


And I tried to restore to another database called "temp", with this command:

/usr/local/mysql/bin/mysqldump --verbose --user=root --password=mypass temp < /Users/Me/Desktop/backup.sql


Here the message after did the restore command:

-- MySQL dump 10.13 Distrib 5.5.17, for osx10.6 (i386)
--
-- Host: localhost Database: temp
-- ------------------------------------------------------
-- Server version 5.5.17

/*!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 */;
-- Disconnecting from localhost...
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2011-11-19 0:07:09

Answer

Mysqldump is for creating backup, not for restoring. To restore use mysql : mysql -u[username] -p[password] [database_name] <path_to_your_backup. Database should be created in advance.

Also, you may probably need to add --routines to mysqldump, by default it doesn't include stored procedures/functions.