I am trying to backup my MySql databases on Windows via a batch file. It works fine.
but i want to remove the default use "database" and create "database" command.from that .sql file which is by default created while creating backup.
these are the lines i want to remove before taking backup for each .sql file
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `database name` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE database name;
Ya I got the answer from mysql official site.
I have used '--databases' in my batch file. to backup all databases.present in server.
just removing that and now it works fine.
--no-create-db
Do not write CREATE DATABASE statements
https://dev.mysql.com/doc/refman/5.6/en/mysqldump.html#option_mysqldump_create-options
Related
My supervisor was given a backup file from our company's cloud mysql database (adminstered by a 3rd party)
The file has a .mysql extension. I can view some of the data using Notepad++ so I know it contains valid data. In my research I discovered this a deprecated extension. Due to some reporting requirements, I was asked to move this data into Excel. I know enough about databases of the five of us in the shop to be considered the "expert" (a scary thought)
Research I've done leads me to believe I would be required to do a LAMP install to convert the mysql file to PDO which I think I can then convert to Excel. That seems like overkill to me.
Is there a more direct route? Load a legacy version of MySQL and hope I can do some conversion in the workbench? The file is a little over 500MB.
I typically develop industrial controls in Python or C#.
-- MySQL dump 10.13 Distrib 5.7.33, for Linux (x86_64)
--
-- Host: localhost Database: company_name
-- ------------------------------------------------------
-- Server version 5.7.33-0ubuntu0.18.04.1
DROP TABLE IF EXISTS `ACTIVEMQ_MSGS`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
.
.
.
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ACTIVEMQ_MSGS` (
`ID` bigint(20) NOT NULL,
`CONTAINER` varchar(250) DEFAULT NULL,
`MSGID_PROD` varchar(250) DEFAULT NULL,
`MSGID_SEQ` bigint(20) DEFAULT NULL,
`EXPIRATION` bigint(20) DEFAULT NULL,
`MSG` longblob,
`PRIORITY` bigint(20) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `ACTIVEMQ_MSGS_MIDX` (`MSGID_PROD`,`MSGID_SEQ`),
KEY `ACTIVEMQ_MSGS_CIDX` (`CONTAINER`),
KEY `ACTIVEMQ_MSGS_EIDX` (`EXPIRATION`),
KEY `ACTIVEMQ_MSGS_PIDX` (`PRIORITY`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
.
.
.
LOCK TABLES `rh_blobs` WRITE;
/*!40000 ALTER TABLE `rh_blobs` DISABLE KEYS */;
INSERT INTO `rh_blobs` VALUES (data....)
INSERT INTO `rh_blobs` VALUES (data....)
Thanks to all for recommendations. Using mysql command line helped me solve the problem.
Install mysql on my desktop (Windows)
start mysql with the following. Entered root password at the prompt
cd c:\program files\mysql\mysql server 5.7\bin
mysql -u root -p
Create and restored the backup/archive file to a new database
create database company-name-report
use company-name-report
source c:\users\user_name\Downloads\company_name.mysql
Following #O. Jones advice, downloaded HeidiSQL and was able to view the data.
Should be a simple task now to export to CSV for use with Excel
Assuming your file contains the text of a bunch of SQL statements, here's what you need to do.
Stand up a MySQL server temporarily.
Run the SQL statements in your file, one after the other in order, against that server.
Issue a SQL statement to write out a comma-separated-value (.csv) file for each table that's populated by that file of yours.
Import those .csv files into Excel.
Get rid of the MySQL server.
The version of the MySQL server you use is almost certainly irrelevant.
MySQL Workbench or the HeidiSQL client program, among many others, give you the tools you need for steps 2-4.
In MySQL Workbench, right-click the table to export and choose Table Data Export Wizard. In the wizard, choose csv export. Choose comma for the field separator, CR for the line separator. Enclose strings in ", the double quote character. And for null and NULL, choose NO.
Several cloud providers offer quick and easy ways to stand up MySQL servers. For example, Digital Ocean offers MySQL servers for pennies an hour. And they charge by the hour. If this little project costs you as much as five US dollars, that will be a surprise.
I want to convert my database to utf-8. What I have done up to now is set the server to read utf-8 and the database is converted by using this query:
ALTER DATABASE database_name CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Now all new information is seen and the things that were broken are now fine. The problem is that the old data is seen as �. This, in my opinion, is due to the fact that the old data is written in windows-1251 (I think at least and I am not 100% sure).
I found out that I need to dump the data:
mysqldump -uroot -p database -r utf8.dump
and then import it:
mysql -uroot -p --default-character-set=utf8 database
mysql> SET names 'utf8'
mysql> SOURCE utf8.dump
This is what I saw from here: https://makandracards.com/makandra/595-dumping-and-importing-from-to-mysql-in-an-utf-8-safe-way
The problem is that I have absolutely no idea where and how to do this.
All I have access is to the web hosting control panel and I have not set up anything on my computer. Therefore, I have no idea how to connect the database to the command shell and so on. What next steps should I do to convert the data to utf-8? Please, any detailed explanation would be great due to the fact that this is the first time for me doing something like this.
// I have a Mac and a Windows machine, but not a Linux at the moment.
Thank you!
The charset and collation of the database are the default for any subsequently created tables. The table setting are the defaults for columns.
For each table, so this:
ALTER TABLE table_name CONVERT TO utf8mb4;
Is there a way to export the tables and data from one schema to another? The manage import/export option asks me to select a server to connect to, which comes up blank. I'm currently connected to a server that my school has rented, specifically for this class, so I don't have any admin rights.
You can create a dump via Data Export in MySQL Workbench and import that right after the export to a new schema. MySQL Workbench allows to override the target schema in a dump.
If you run into troubles importing your data into the new schema, like not getting any data in it, a workaround might be needed. I ran an export of a schema from MySQL workbench to a .sql file to later import it in a different schema and the problem was that the .sql file exported maintained the previous schema.
So if you find this at the beginning of the .sql exported file:
CREATE DATABASE IF NOT EXISTS `old_schema` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `old_schema`;
Replace it with this:
CREATE DATABASE IF NOT EXISTS `new_schema` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `new_schema`;
That will do the trick. In some situations, your .sql file might be of a few hundreds MB so you will have to wait a little until it opens up in your editor. This code should be at the beginning of the file though so it is easy to find.
I hope it helps!
in 6.0 and up, it looks like the dump writes out individual tables in a directory that you name the dump. All of the schema and table names are defaulted to your schema that you exported from (as you've noted.) In order to facilitate an import to a new schema, simply run the following in your dump directory:
find . -type f -exec sed -i 's/your_export_schema/your_different_schema_name/g' {} \;
Be careful though, you'll bone your self if you have data in your export that has your old schema name in it.
I noticed that the question was about the Workbanch, but be aware that the phpMyAdmin have this ability directly, in the database operations.
Last week I migrated my db in another platform. I did a mysqldump export from phpmyadmin panel and then I imported it in a new platform using the bigdump script.
The sql dump file that I have imported was originally stored in a db that was setting in this manner:
MySQL charset: UTF-8 Unicode (utf8)
MySQL connection collation: utf8_unicode_ci
I exported the db choosing utf8 character set but if I look inside the mysqldump file for every table appears:
DEFAULT CHARSET=latin1
Now I have a problem with the accented letter (like à, è, ò, ì) that are displayed like ò , Ã...etc.
For manage my new db I use MySQL Workbench and if i prompt:
show variables like 'char%';
I see that all the values are set in utf8.
How can I solve the problem? I'm not a Mysql and db expert!
You can try changing the current character set of a table to the original:
alter table TABLE_NAME convert to character set utf8 collate utf8_unicode_ci;
Your tables seem to use latin1, despite the utf8 settings you mentioned. So you have several options here:
Take the created dump as is and send it to the server using the latin1 connection charset (not utf8). This will however create the tables with latin1 charset as they are on the source server.
Convert the dump to utf-8 if you have a tool that can do it. You have to change the charset settings for your tables in the script too, though.
Convert your tables to utf8 and do the dump again.
Combine 1 + 3, but convert your target tables instead. Useful if you cannot change the source tables.
Have you actually tried MySQL Workbench to restore the dump to your new server? I'm quite sure it should be able to handle this case with a latin1 encoded backup. See Server Administration section -> Data Import/Restore.
I'm moving a locally developed wordpress site to a client's server so I'm trying to export the local database and import it to the server. I exported the .sql file according to the instructions here http://codex.wordpress.org/Backing_Up_Your_Database but I keep getting this error when importing:
DROP TABLE IF EXISTS `wp_commentmeta` ;
MySQL said: Documentation
#1046 - No database selected
Any help very much appreciated. Thanks!
Like the two other answers say: I wasn't importing the backup file to a particular database. I had to create a new database and upload the file to that, and it worked fine.
Try sticking a use statement in front of it:
USE MyWordpressDBName;
DROP TABLE IF EXISTS `wp_commentmeta` ;
MySql Use Reference
You posted a link describing how to backup your database. But the problem you have is not with the backup but with the restore, so you should look at the instructions on how to restore your database.
Luckily that site also has instructions on how to restore a database from a backup (any guide which only tells you how to backup but not how to restore is IMHO a waste of time). Try following the instructions on this page:
http://codex.wordpress.org/Restoring_Your_Database_From_Backup
In particular notice this command near the end of the tutorial:
mysql -h mysqlhostserver -u mysqlusername -p databasename < blog.bak.sql
The database name must be specified.