I would like to create a zip file for my NetBeans project which has a database named hoteldb. The steps which I know are:
1)Start the SQL server (type mysqld --standalone in a command window)
2)In a new command window type: mysqldump hoteldb -u root
3)Assuming everything worked correctly in step 2(the result must be something like the following code) I should now give the command: mysqldump hoteldb -u root > dump.sql
I am using MySql5.5 and these steps are not working. Is something missing or what I must change in these lines of code?
The output of step 2 should be something like:
-- MySQL dump 10.11
--
-- Host: localhost Database: hoteldb
-- ------------------------------------------------------
-- Server version 5.0.51b-community
/*!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 `reservation`
--
......
--
-- Dumping data for table `reservation`
--
......
--
-- Table structure for table `room`
--
......
--
-- Dumping data for table `room`
--
......
/*!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 2010-11-19 11:29:31
The syntax of you mysqldump command looks a little incorrect.
It should read:
mysqldump -u root -p<your_password> hoteldb > dump.sql;
You can then zip up the resulting dump.sql file.
Also, it could be that mysqld is not starting correctly? Check this by starting it up as you've described and then trying to login as root.
Related
I've created a copy of a database and changed the collation and charset to utf8mb4 (originally it was latin1), then used mysqldump to create a script for a Flyway database migration.
When I run the following script
-- MySQL dump 10.13 Distrib 5.5.62, for Win64 (AMD64)
--
-- Host: localhost Database: feedback
-- ------------------------------------------------------
-- Server version 8.0.15
/*!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 utf8mb4 */;
/*!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 */;
--
-- Dumping data for table `COMPONENT_GROUP`
--
LOCK TABLES `COMPONENT_GROUP` WRITE;
/*!40000 ALTER TABLE `COMPONENT_GROUP` DISABLE KEYS */;
INSERT INTO `COMPONENT_GROUP` VALUES ('AAAB','AAA - MOTOR','LUBRIFICAÇÃO DO MOTOR','LUBRIFICAÇÃO DO MOTOR',NULL,NULL,20181219,1)
UNLOCK TABLES;
/*!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 2019-05-22 13:07:38
flyway shows messages like these:
WARNING: DB: Invalid utf8 character string: 'C7C34F' (SQL State: HY000 - Error Code: 1300)
WARNING: DB: Incorrect string value: '\xC3O FUN...' for column 'claimed_name_pt' at row 10 (SQL State: HY000 - Error Code: 1366)
When I run the dump script using tools like SQLyog and MySQL Workbench the data is correctly inserted, so how can I fix that for Flyway?
Found the missing part to fix the migration issue. I had to add encoding settings to the Flyway's connection string:
FLYWAY_URL="jdbc:mysql://${db_instance.default.address}:3306/${mysql_database.db-app.name}?characterEncoding=UTF-8&useUnicode=true"
steps:
got bananas database backup:
mysqldump -u root -p bananas > /var/www/site.com/bananas_backup.sql
I created a new empty datase;
mysql> CREATE DATABASE bananas2019;
now appplying bananas backup into bananas 2019;
mysqldump -u root -p bananas2019 < bananas_backup.sql
got this:
-- MySQL dump 10.13 Distrib 5.7.24, for Linux (x86_64)
--
-- Host: localhost Database: bananas2019
-- ------------------------------------------------------
-- Server version 5.7.24-0ubuntu0.18.04.1
/*!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 */;
/*!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 2018-11-30 19:16:05
I went to check my database and still empty with no data why?
my backup it is in the right directory and has data, already checked this.
what i am doing wrong?
mysqldump just dumps data, it's not used for importing. For that you can use mysql:
mysql -u root -p bananas2019 < bananas_backup.sql
I created a backup of mysql database from my live site using mysqldump and downloaded the SQL file (~960MB). I've a local install of MariaDB and I tried importing the database again using mysqldump. I am getting following error:
-- MySQL dump 10.16 Distrib 10.2.10-MariaDB, for osx10.13 (x86_64)
--
-- Host: localhost Database: original
-- ------------------------------------------------------
-- Server version 10.2.10-MariaDB
/*!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 */;
/*!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 2017-12-01 8:27:08
I'm not allowed to make any changes to the live DB and would really appreciate if there's a way to import this DB successfully to my local DB.
Thank you in advance for your cooperation.
As noted in comments,
That's not an error, it's just comments in the dump file.
Additionally,
You don't use mysqldump to import, only to export. You use mysql < filename to import
From this question: MariaDB i am not able to import this dump file
You import the dump like so:
mysql -u root -p --database=db_name < dumpfile.sql
i am trying to backup my database using mysqldump
code
exec('D:\wamp\bin\mysql\mysql5.6.17\bin\mysqldump -h'.$HOSTNAME.' -u'.$DBUSER.' -p'.$DBPASS.' dbname -t tablename > '.$mysqlExportPath.' --log-error="DumpError.txt');
and i got following output
-- MySQL dump 10.13 Distrib 5.6.17, for Win32 (x86)
--
-- Host: localhost Database: database name
-- ------------------------------------------------------
-- Server version 5.6.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 */;
Dump Error
mysqldump: Couldn't find table: "13:44:43.sql"
1.problem is mysqldump not writing table structure and data in output.
2.table name is display as 13:44:43.sql where as my table name is like abc.
3.if i run same code with same tablename again table name in dump error changes with other numeric ex. next time it is 13:45:08.sql.
plz help i am not able to find that numeric table name problem any ware.
solved.
date(); have space between date and time so time was taken as table name due to space.
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
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.