Microsoft SQL DB to MySQL DB - mysql

I have seen tons of post on this, but I am not very familiar with the process and nothing has worked.
My basic problem is I am trying to get data from a Microsoft SQL database (Using Microsoft Management Studio 2008) to convert and use in a MySQL database (using MySQL Workbench)
I have tried to dump the .sql file but when I try to import into MySQL Workbench I get errors about it not being in the UTF-8 format. I tried several ways to get it to be that encoding (such as notepadd++ converting I saw suggested everywhere), but nothing seemed to work.
If I run it, I get this error:
ERROR: ASCII '\0' appeared in the statement, but this is not
allowed unless option --binary-mode is enabled and mysql is
run in non-interactive mode.
Again I looked up fixed for this, but could not get it.
I have tried a few options, just no success, so looking for some ideas or guidance with this area I do not have much experience in.
UPDATE:
The problem now is that the sql file I export from Management Studio is not accepted as a valid query in Workbench.
For example the brackets are not accepted and such.

I bet your encoding is not supported in MySQL WorkBench.
You can change the encoding when saving a .sql file.
Select File|Save.sql As to invoke the save as dialog.
Notice that the Save button on the lower right hand side has a drop down icon to indicate options.
Select the drop down icon and choose the "Save with Encoding" context memu item.
Select an encoding that works in MySQL Workbench.

Related

How come doing a find/replace on sql dump and importing it gives error #2006?

I have the sql dump for a wordpress install that lives on a domain. I need to make some changes to the site so I have set up a localhost using MAMP.
If I import the sql dump "as-is" it imports without a problem. However I need to change all the URL's in the sql dump to point to localhost instead.
When I use Aptana to do a replace all on the sql file from http://example.com to http://localhost/example and try to import the modified file to mysql I get the error "#2006 - MySQL server has gone away"
What is the problem here? I have temporarily fixed by overriding my hosts file for example.com to point to my localhost but this is not a long term viable option.
I am aware this error usually occurs for files that are too large or the server not responding but I am always able to import the non-modified version of the sql. Also there are 9538 replaces being done so I cannot go through 1 by 1 to find the culprit.
Thank you
(Just realized that it doesn't relate DIRECTLY to your problem, but you still need this info if you are doing Search and Replace in your MySQL dump).
Data in the WP database is serialized. You can't just search and replace.
You can't just change the data without re-serializing it.
There are scripts and services that allow you to do a proper Search and Replace.
I usually use this tool (git repository here), and it works perfectly. There are also a couple plugins that work, and just discovered this service from a theme creation company that does the same thing.
Good luck and happy wordpressing.

Disabling data infile breaks MySQL

I run a MySQL server off my computer and have been playing around with it and PHP to access stored data. I find it works a lot better than Excel and is more cross platform/portable with export to HTML tables.
I recently was reading on how to secure MySQL and came across this article:
http://www.greensql.com/content/mysql-security-best-practices-hardening-mysql-tips
which has a section suggesting to disable the data infile in the mysql.conf file using:
set-variable=local-infile=0
However, after doing this, I was unable to get MySQLD to start at all. I had to remove this line to get SQL running again. Using MySQL 5.5.35-0ubuntu0.13.10.2 (Ubuntu)
Anyone know another way to patch this vulnerability without breaking MySQL?
http://dev.mysql.com/doc/refman/5.0/en/program-variables.html says:
Before MySQL 4.0.2, the only syntax for setting program variables was --set-variable=option=value (or set-variable=option=value in option files). ... This syntax still is recognized, but is now deprecated and is removed in MySQL 5.5.
In other words, in MySQL 5.5 and later, don't use set-variable. Just set the variable:
local-infile=0

Convert localhost database to server database

This may be stupid but am using MySQL on a localhost using XAMPP and I've finished my app and bought a server so how can I upload my localhost database to the server?
What your looking for is the "mysqldump" command. simply type 'man mysqldump' which will give you the various options available.
This command will basically produce a text file and with the proper flags include within that file both the complete sequence of commands to recreate your database tables and load the data.
If I recall correctly there are at least two different methods of restoring the data on the other end with the commands being "source" and "load from file" if I'm recalling things right.
Either way the details I've provided should be enough to get you through it with at worst having to drop one or two of the words into Google for a syntax reference.

MySQL Workbench skip pulling schema list on opening a SQL editor

Is there a way to make the Workbench skip caching the schema information on SQL Editor load? I've got tons of tables in my database (not to mention the server is half way across the world) and it takes ages to fire up the SQL Editor.
This would be something akin to --skip-auto-rehash (or the -A switch) on the command line but for the life of me I couldn't find anything on the Workbench or connection options to do this.

How to import a SQL Server .bak file into MySQL?

The title is self explanatory. Is there a way of directly doing such kind of importing?
The .BAK files from SQL server are in Microsoft Tape Format (MTF) ref: http://www.fpns.net/willy/msbackup.htm
The bak file will probably contain the LDF and MDF files that SQL server uses to store the database.
You will need to use SQL server to extract these. SQL Server Express is free and will do the job.
So, install SQL Server Express edition, and open the SQL Server Powershell. There execute sqlcmd -S <COMPUTERNAME>\SQLExpress (whilst logged in as administrator)
then issue the following command.
restore filelistonly from disk='c:\temp\mydbName-2009-09-29-v10.bak';
GO
This will list the contents of the backup - what you need is the first fields that tell you the logical names - one will be the actual database and the other the log file.
RESTORE DATABASE mydbName FROM disk='c:\temp\mydbName-2009-09-29-v10.bak'
WITH
MOVE 'mydbName' TO 'c:\temp\mydbName_data.mdf',
MOVE 'mydbName_log' TO 'c:\temp\mydbName_data.ldf';
GO
At this point you have extracted the database - then install Microsoft's "Sql Web Data Administrator". together with this export tool and you will have an SQL script that contains the database.
MySql have an application to import db from microsoft sql.
Steps:
Open MySql Workbench
Click on "Database Migration" (if it do not appear you have to install it from MySql update)
Follow the Migration Task List using the simple Wizard.
I did not manage to find a way to do it directly.
Instead I imported the bak file into SQL Server 2008 Express, and then used MySQL Migration Toolkit.
Worked like a charm!
In this problem, the answer is not updated in a timely. So it's happy to say that in 2020 Migrating to MsSQL into MySQL is that much easy. An online converter like RebaseData will do your job with one click. You can just upload your .bak file which is from MsSQL and convert it into .sql format which is readable to MySQL.
Additional note: This can not only convert your .bak files but also this site is for all types of Database migrations that you want.
Although my MySQL background is limited, I don't think you have much luck doing that. However, you should be able to migrate over all of your data by restoring the db to a MSSQL server, then creating a SSIS or DTS package to send your tables and data to the MySQL server.
hope this helps
I highly doubt it. You might want to use DTS/SSIS to do this as Levi says. One think that you might want to do is start the process without actually importing the data. Just do enough to get the basic table structures together. Then you are going to want to change around the resulting table structure, because whatever structure tat will likely be created will be shaky at best.
You might also have to take this a step further and create a staging area that takes in all the data first n a string (varchar) form. Then you can create a script that does validation and conversion to get it into the "real" database, because the two databases don't always work well together, especially when dealing with dates.
The method I used included part of Richard Harrison's method:
So, install SQL Server 2008 Express
edition,
This requires the download of the Web Platform Installer "wpilauncher_n.exe"
Once you have this installed click on the database selection ( you are also required to download Frameworks and Runtimes)
After instalation go to the windows command prompt and:
use sqlcmd -S \SQLExpress (whilst
logged in as administrator)
then issue the following command.
restore filelistonly from
disk='c:\temp\mydbName-2009-09-29-v10.bak';
GO This will list the contents of the
backup - what you need is the first
fields that tell you the logical names
- one will be the actual database and the other the log file.
RESTORE DATABASE mydbName FROM
disk='c:\temp\mydbName-2009-09-29-v10.bak' WITH MOVE 'mydbName' TO
'c:\temp\mydbName_data.mdf', MOVE
'mydbName_log' TO
'c:\temp\mydbName_data.ldf'; GO
I fired up Web Platform Installer and from the what's new tab I installed SQL Server Management Studio and browsed the db to make sure the data was there...
At that point i tried the tool included with MSSQL "SQL Import and Export Wizard" but the result of the csv dump only included the column names...
So instead I just exported results of queries like "select * from users" from the SQL Server Management Studio
SQL Server databases are very Microsoft proprietary. Two options I can think of are:
Dump the database in CSV, XML or similar format that you'd then load into MySQL.
Setup ODBC connection to MySQL and then using DTS transport the data. As Charles Graham has suggested, you may need to build the tables before doing this. But that's as easy as a cut and paste from SQL Enterprise Manager windows to the corresponding MySQL window.
For those attempting Richard's solution above, here are some additional information that might help navigate common errors:
1) When running restore filelistonly you may get Operating system error 5(Access is denied). If that's the case, open SQL Server Configuration Manager and change the login for SQLEXPRESS to a user that has local write privileges.
2) #"This will list the contents of the backup - what you need is the first fields that tell you the logical names" - if your file lists more than two headers you will need to also account for what to do with those files in the RESTORE DATABASE command. If you don't indicate what to do with files beyond the database and the log, the system will apparently try to use the attributes listed in the .bak file. Restoring a file from someone else's environment will produce a 'The path has invalid attributes. It needs to be a directory' (as the path in question doesn't exist on your machine).
Simply providing a MOVE statement resolves this problem.
In my case there was a third FTData type file. The MOVE command I added:
MOVE 'mydbName_log' TO 'c:\temp\mydbName_data.ldf',
MOVE 'sysft_...' TO 'c:\temp\other';
in my case I actually had to make a new directory for the third file. Initially I tried to send it to the same folder as the .mdf file but that produced a 'failed to initialize correctly' error on the third FTData file when I executed the restore.
The .bak file from SQL Server is specific to that database dialect, and not compatible with MySQL.
Try using etlalchemy to migrate your SQL Server database into MySQL. It is an open-sourced tool that I created to facilitate easy migrations between different RDBMS's.
Quick installation and examples are provided here on the github page, and a more detailed explanation of the project's origins can be found here.