Browse a SQL-Dump file without importing it into a DBMS? - sql

Is somebody aware of a tool that lets me browse MySQL-Files without having to import them into my database system?
I'm looking for an easy way to inspect MySQL Backups quickly without having to import them - but still being nicely displayed, so viewing the SQL source is not really an option.
Maybe there's a program that takes the SQL dump and automatically imports it into a temporary database, then presenting it in an interface similar to HeidiSQL (or any other SQL-Gui-Tool).

Why are you eliminating the obvious solution? You just need to load the backup into a mysql database. Either load the backup into a separate mysql instance, or if your backup is of just one database (i.e. you didn't pass --databases or --all-databases to mysqldump), load it into a database of a different name.

I came here looking for an answer to the same question, because it can be cumbersome to wait to load a 20 GB sql dump just for inspection and drop again. While I hope to find a standalone shortcut tool, best I can recommend is a cocktail of linux cli text manipulation tools like grep, sed, and cut. Some useful output could be:
What tables are being created/inserted into?
Are the mysqldump INSERTs one line-per-record or all stuffed into one? (Because this can affect other things like)
How many rows are being inserted into table XYZ?
What is some representative data being inserted into table XYZ?
What is the ABC column value for the last row inserted into table XYZ?
Good luck!

Related

Copying database from one computer to another

Me and my friend both have sql server 2012. I have a database where I would like to copy over most of the tables into a database on my friends laptop. I am not sure not sure how to go about doing this?
I know in sql server that I can copy over data from one table in say database A to database B using the line below.
select * into database_a.dbo.MyTable from database_a.dbo.MyTable
What is the best way to connect the two laptops?
You could take a full backup and give it to him to restore. Or you could give him a copy of the *.mdf file and let him attach it to his DB.
There are two main options, one is to back up the database and send it to your friend. To do this right click on the database, Tasks and Backup. The problem with this approach is that if you're running even slightly different versions you may have issues.
The alternative is to script the database. To do this right on the database, click Tasks and Generate Scripts. Make sure you choose to script data and schema from the advanced options.
The latter is my preferred approach (as it's much more editable and human readable).

Fastest way to copy a single large (30,000 rows) table from one database to another?

I've got a large table in a SQL Server 2005 database and I'd like to copy it over to another database.
What's the fastest way to do this? Is there a shortcut to linking servers and doing inserts?
The EXPORT function of Sql Server Management Studio Express.
http://www.microsoft.com/downloadS/details.aspx?familyid=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796&displaylang=en
You need specify the destination server and tables, and the tool do all you need.
Try a command line utility called bcp for a bulk export, and Bulk Insert for the import.
See About Bulk Import and Bulk Export operations.
to improve the speed, disable all forms of logging and drop any constraints or referential integrity.
I don't want to hit anyone here. But so far, I didn't find a fast way to copy table.
I am working on a big project and I usually handle table with 3-7 millions rows. When I want to back the table, my headache come.
Up to now:
1. BCP is definitively the fastest tool. But it can only handle simple datatype correctly. If you have nvarchar and has some strange chars '"&#2. It ususally doesn't work. Due to the high risk work with bcp. I recommend you forget it but only use it for very simple table.
It is really SUPER fast.
Never mention export/import wizard or command. It is one of the lowest tool I has used. And it may broke during transport.
So far, is fastest way is to detach you database, copy it by harddisk(usually 20M/s). Even you data occupy 6G disk. it only take 300s ~ 5 minutes. And attach it on another machine. Remove tables you don't want. If you use any method suggest by others, I promise you won't get the transmission in an hour.
I think best option is to use export and import .

Easiest way to copy a MySQL database?

Does anyone know of an easy way to copy a database from one computer to a file, and then import it on another computer?
Here are a few options:
mysqldump
The easiest, guaranteed-to-work way to do it is to use mysqldump. See the manual pages for the utility here:
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
Basically, it dumps the SQL scripts required to rebuild the contents of the database, including creation of tables, triggers, and other objects and insertion of the data (it's all configurable, so if you already have the schema set up somewhere else, you can just dump the data, for example).
Copying individual MyISAM table files
If you have a large amount of data and you are using the MyISAM storage engine for the tables that you want to copy, you can just shut down mysqld and copy the .frm, .myd, and .myi files from one database folder to another (even on another system). This will not work for InnoDB tables, and may or may not work for other storage engines (with which I am less familiar).
mysqlhotcopy
If you need to dump the contents of a database while the database server is running, you can use mysqlhotcopy (note that this only works for MyISAM and Archive tables):
http://dev.mysql.com/doc/refman/5.0/en/mysqlhotcopy.html
Copying the entire data folder
If you are copying the entire database installation, so, all of the databases and the contents of every database, you can just shut down mysqld, zip up your entire MySQL data directory, and copy it to the new server's data directory.
This is the only way (that I know of) to copy InnoDB files from one instance to another. This will work fine if you're moving between servers running the same OS family and the same version of MySQL; it may work for moving between operating systems and/or versions of MySQL; off the top of my head, I don't know.
You may very well use SQL yog - a product of web yog.. it uses similar techniques mentioned above but gives you a good GUI making you know what you are doing. You can get a community project of the same or a trial version from site
http://www.webyog.com/en/downloads.php#sqlyog
This has option for creating backups to a file and restoring the file into new server. Even better option of exporting database from one server to another is there..
Cheers,
RDJ

What is the easiest way to copy a database from one Informix IDS 11 Server to another

The source database is quite large. The target database doesn't grow automatically. They are on different machines.
I'm coming from a MS SQL Server, MySQL background and IDS11 seems overly complex (I am sure, with good reason).
One way to move data from one server to another is to backup the database using the dbexport command.
Then after copying the backup files to the destination server run the dbimport command.
To create a new database you need to create the DBSpace for the new database using the onmonitor tool, at this point you could use the existing files from the other server.
You will then need to create the database on the destination server using the dbaccess tool. The dbaccess tool has a database option that allows you to create a database. When creating the database you specify what DBSpace to use.
The source database may be made up of many chunks which you will also need to copy and attach to the new database.
The easiest way is dbexport/dbimport, as others have mentioned.
The fastest way is using onpload, the High Performance Loader. If you have lots of data, but not a ridiculous number of tables, this is definitely worth pursuing. There are some bits and pieces on the IIUG site that may be of assistance in scripting the HPL to generate all the config you'll need.
You have a few choices.
dbexport/dbimport
onunload/onload
HPL (high performance loader) options.
I have personally used onunload/onload and dbexport/dbimport. I have not used HPL. I'm using IDS 10.
onunload/onload IBM docs
Back up the raw database to disk or tape in page size chunks
faster (especially if you go to disk)
Issues if the the database servers are on different operating systems or hardware or if they just have different page sizes.
dbexport/dbimport IBM docs
backup the database in delimited ascii files
writes an ascii schema of the database including all users, tables, views, indexes, etc. Everything about the structure of the database into one huge plain text file.
separate plain text files for each table of the database as well
not so fast
issues on dbimport on any table that has bad data, any view with incorrect syntax, etc. (This can be a good thing, an opportunity to identify and clean)
DO NOT LEAVE THIS TAPE ON THE FRONT SEAT OF YOUR CAR WHEN YOU RUN INTO THE STORE FOR AN ICE CREAM (or you'll be on the news). Also read ... Not a very secure way to be moving data around. :)
Limitation: Requires exclusive access to the source database.
Here is a good place to start in the docs --> Migration of Data Between Database Servers
have you used the export tool ? There used to be a way if you first put the db's into quiescent mode and then you could actually copy the DBSpaces across (dbspaces tool I think... its been a few years now).
Because with informix you used to be able to specify the DBSpaces(s) to used for the table (maybe even in the alter table ?).
Check - dbaccess tool - there is an export command.
Put the DB's into quiesent mode or shut down, copy the dbspaces and then attach table telling it to point to the new dbspaces file. (the dbspaces tool could be worth while looking at.. I have manuals around here. they are 9.2, but it shouldn't have changed too much).
If both the machines use the same version of IDS then another option would be to use ontape to take a backup on one machine one machine and restore on another. You can use the STDIO option and then just stream the backup onto the other machine where the restore could just restore from the STDIO.
From the "Data Replication for High Availability and Distribution" redbook:
ontape -s -L 0 -F | rsh secondary_server "ontape –p"
You could also create a passwordless ssh connection b/w the hosts and transfer in a more secure way.

Create a database from another database?

Is there an automatic way in SQL Server 2005 to create a database from several tables in another database? I need to work on a project and I only need a few tables to run it locally, and I don't want to make a backup of a 50 gig DB.
UPDATE
I tried the Tasks -> Export Data in Management studio, and while it created a new sub database with the tables I wanted, it did not copy over any table metadata, ie...no PK/FK constraints and no Identity data (Even with Preserve Identity checked).
I obviously need these for it to work, so I'm open to other suggestions. I'll try that database publishing tool.
I don't have Integration Services available, and the two SQL Servers cannot directly connect to each other, so those are out.
Update of the Update
The Database Publishing Tool worked, the SQL it generated was slightly buggy, so a little hand editing was needed (Tried to reference nonexistent triggers), but once I did that I was good to go.
You can use the Database Publishing Wizard for this. It will let you select a set of tables with or without the data and export it into a .sql script file that you can then run against your other db to recreate the tables and/or the data.
Create your new database first. Then right-click on it and go to the Tasks sub-menu in the context menu. You should have some kind of import/export functionality in there. I can't remember exactly since I'm not at work right now! :)
From there, you will get to choose your origin and destination data sources and which tables you want to transfer. When you select your tables, click on the advanced (or options) button and select the check box called "preserve primary keys". Otherwise, new primary key values will be created for you.
I know this method can hardly be called automatic but why don't you use a few simple SELECT INTO statements?
Because I'd have to reconstruct the schema, constraints and indexes first. Thats the part I want to automate...Getting the data is the easy part.
Thanks for your suggestions everyone, looks like this is easy.
Integration Services can help accomplish this task. This tool provids advanced data transformation capabilities so you will be able to get exact subset of data that you need from large database.
Assuming that such data is needed for testing/debugging you may consider applying Row Sampling to reduce amount of data exported.
Create new database
Right click on it,
Tasks -> Import Data
Follow instructions