I am using mysql server 5.5.33 inside and a IIS 6 in a windows machine. I am using this php code to create a dump .sql file:
$command ="C:\\Program^ Files\\MySQL\\MySQL^ Server^ 5.5\\bin\\mysqldump -u root -pMYPASSWORD myDB >C:\mysites\my_source\mydir\myDB_dump.sql";
echo shell_exec("$command 2>&1 ; echo $?" );
Then I got a file myDB_dump.sql where I can read:
mysqldump: Got error: 1049: Unknown database 'files\mysql\mysql' when selecting the database
-- MySQL dump 10.13 Distrib 5.5.33, for Win64 (x86)
--
-- Host: localhost **Database: Files\MySQL\MySQL**
-- ------------------------------------------------------
-- Server version 5.5.33-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 */;
I do not understand. The database is there, but it seems that it is not found. What am I doing wrong?
Others had the same issue, but not solved Copying issue with mysqldump and MYSQL DBDump Error message
Update 2016 This is what I did:
- Set the environment variables for MySQL. Linux or Windows.
- After sit , use this code
shell_exec("mysqldump -uroot -pPASSWORD --create-options -d $dbName > $pathName");//Where $dbName is the name of database and $pathName is "yourPath/mydump.sql"
- Or try the code with the full path to mysqldump if you where not able to set environment variables. Example: If you have MySql inside xampp, the full path will be like this:
shell_exec("C:\\xampp\\mysql\\bin\\mysqldump -uroot -pPASSWORD --create-options -d $dbName > $pathName");
And now this is what I got as result:
-- MySQL dump 10.13 Distrib 5.6.26, for Win32 (x86)
--
-- Host: localhost Database: drSET2014
-- ------------------------------------------------------
-- Server version 5.6.26
/*!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 */;
--
-- Table structure for table `address`
--
DROP TABLE IF EXISTS `address`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
...