Synchronize a file from MySQL database to MS SQL Server - mysql

Is there a way to transfer a file from a MySQL database to a MSSQL Server using Nodejs?
Say, I have two applications,
Application A uses MySQL database and nodejs for the backend.
Application B uses MSSQL Server database.
I uploaded an image/document from Application A. I want to transfer/synchronize that image/document to Application B from the source code of Application A.
I've tried using mssql client for Node.js. It works as the rows from MySQL database is transferred to MSSQL Server database.
The problem is when I download the image/document from Application B, the image/document is a plain text with a file size of 0 byte.
Any suggestions or solutions that can help?
Thank you.

Requirements
Before starting the database migration, you will need the following software on your Windows machine :
A running MS SQL Server instance.
A running MySQL Server instance (this depends on your environment, we work with the MySQL server available in Xampp ). The idea is basically to have a MySQL server instance accessible on port 3306.
SQL Server Management Studio installed.
MySQL Workbench . This tool will allow you to migrate the data at the end.
1. Identify the database you are trying to migrate.
As a first step, you must verify that the database you want to migrate is exposed in your SQL Server instance. The easiest way to do this is through the SSMS tool. SQL Server Management Studio (SSMS) is an integrated environment for managing any SQL infrastructure, from SQL Server to Azure SQL Database. SSMS provides tools to configure, monitor and manage SQL Server instances and databases. Use SSMS to deploy, monitor and update the data layer components used by your applications, as well as create queries and scripts.
Open SSMS and access the database engine with the default Windows authentication (or from the connection you want to access) :
Connect to the server and browse the databases in the object browser. In our case, we want to export the my_database database, which, as you can see, is available in the Databases directory :
Now that you know that the database is accessible on the server, we will start with the migration using MySQL Workbench.
2. Start with the migration in MySQL Workbench
MySQL Workbench is a unified visual tool for database architects, developers and administrators. MySQL Workbench provides data modeling, SQL development and comprehensive administration tools for server configuration, user management, backup and much more. MySQL Workbench is available on Windows, Linux and Mac OS X.
Start MySQL Workbench and access the migration wizard from the toolbar (in this tutorial, we use MySQL Workbench 8.0) :
After opening the wizard, click on start migration :
This will open the source selection form. Here you will need to select SQL Server as the source relational database management system (RDBMS). A relational database management system (RDBMS) is a collection of programs and capabilities that allow IT teams and others to create, update, manage and otherwise interact with a relational database, most of which use Structured Query Language (SQL) to access the database. In our case, as mentioned in the article, we will migrate from a Microsoft SQL Server database to a MySQL database, so it will be the source. In our example, we have the MS SQL Server configured on the same computer and it automatically authenticates with Windows Authentication, if your server is hosted remotely, you will need to change the parameters according to your needs. You can test the connection :
And if you are successful, you can continue with the next step of configuring the target RDBMS, which means MySQL. As we mentioned at the beginning of the article, we assume that you already have a MySQL server configured and running in the background, in our case we used Xampp's MySQL server, which allows you to start/stop it with a control panel. The idea is basically to know the credentials to access the running MySQL instance, which in Xampp is accessible with a rootuser and an empty password :
If you are connecting to another MySQL server, you can configure it with SSH keys, etc. Now that both connections are established, you can proceed to the next step which fetches a list of schemas from the source RDBMS. This will create a list that can be toggled with all databases in the SQL Server instance, where you must select the database you want to migrate (as well as the schema name mapping method) :
In our case, we only want to work with the my_database database, so we will extract only that database. Now, if you continue and everything works as expected, you will now see the Source Objects window, which basically allows you to filter which tables you want to migrate or not, normally we would like to migrate them all :
Click next and you will see the migration page, which allows you to pre-check the MySQL script for each table and if there are warnings or errors that you need to correct manually, they will be highlighted in the list. For example, in our case, we have a warning (when importing it will be an error) that specifies a problem with the migration, if we read the code we will see a syntax error of incompatibility with the VISIBLEkeyword. In our example, simply removing that keyword from the lines will allow us to import the scripts without any problem :
After manually correcting the warnings and applying the changes, you can finally export the database structure to a file (.sql) or create the database in the target RDBMS (MySQL Server). In our case, it is easier to import it directly to the server, so we will choose Create schema in target RDBMS (you can export it to a file if you wish) :
Before MySQL workbench starts with the migration, it will check again for errors and warnings; if there are still any, you must manually correct them again :
Click on Recreate object, this will take you to the previous step to build the schematic once again, click next and if everything is successful you will see, everything should be marked as correct :
Finally, all that is left is the data. We already migrated the database structure, so now we need to transfer all the data:
Since we are working with both servers on the same computer, we can make an online copy of the data from the SQL Server database to the MySQL database. Click next and the data migration will start :
Once finished, you will now have the original SQL database in MySQL format on the server. You can now access your MySQL server, where you will find the database available.

Introduction
To integrate any database with nodejs, you need a driver package or you can call it npm module which will provide you with a basic API to connect to the database and perform interactions. The same goes for mssql database, here we will integrate mssql with nodejs and perform some basic queries on SQL tables.
Remarks
We have assumed that we will have a local instance of the mssql database server running on the local machine. You can refer this document to do the same.
Also make sure that the appropriate user created with added privileges as well.
Connecting to SQL via. mssql npm module
We will start by creating a simple node application with a basic structure and then connecting to the local SQL server database and performing some queries on that database.
Step 1: Create a directory / folder with the name of the project you are trying to create. Initialize a node application with the npm init command which will create a package.json in the current directory.
mkdir mySqlApp
//folder created
cd mwSqlApp
//change to newly created directory
npm init
//answer all the question ..
npm install
//This will complete quickly since we have not added any packages to our app.
Step 2: Now we will create an App.js file in this directory and install some packages that we will need to connect to sql db.
sudo gedit App.js
//This will create App.js file , you can use your fav. text editor :)
npm install --save mssql
//This will install the mssql package to you app
Step 3: Now we will add a basic configuration variable to our application that will be used by the mssql module to establish a connection.
console.log("Hello world, This is an app to connect to sql server.");
var config = {
"user": "myusername", //default is sa
"password": "yourStrong(!)Password",
"server": "localhost", // for local machine
"database": "staging", // name of database
"options": {
"encrypt": true
}
}
sql.connect(config, err => {
if(err){
throw err ;
}
console.log("Connection Successful !");
new sql.Request().query('select 1 as number', (err, result) => {
//handle err
console.dir(result)
// This example uses callbacks strategy for getting results.
})
});
sql.on('error', err => {
// ... error handler
console.log("Sql database connection error " ,err);
})
Step 4: This is the easiest step, where we start the application and the application will connect to the SQL server and print some simple results.
node App.js
// Output :
// Hello world, This is an app to connect to sql server.
// Connection Successful !
// 1

Related

Creating custom MySQL servers in VB.NET at runtime

I was wondering if it is possible to create custom MySQL servers in VB.NET while working in visual studio at runtime so that if the server already exists it connects and if it isn't there, the code creates the server. I have searched for this everywhere but couldn't find anything. I would appreciate it a lot if someone guides me to the right path.
You could certainly write some .net code to start a MySQL server on your Windows box when an attempt to connect fails. You simply get a cmd.exe console with administrator privileges and give the command net start mysql.
But MySQL must already be installed on the box for that to work.
You might investigate Sqlite. It provides SQL locally to a .net program, storing your tables in a file called whatever.db. It has very similar .net API access to MySQL's Connector/Net and SQL Server's connector. It's in a NuGet package.
I don't completely understand your "custom MySQL servers" requirement. Sqlite gives you a way to use SQL in your application without connecting to a shared server. That may do what you need.
MySQL does have a CREATE SERVER statement in its SQL dialect. The purpose of this statement is to create a connection to another, remote, MySQL server. With that connection you can use the FEDERATED storage engine to access tables in the remote server. Of course, there is no way to run this CREATE SERVER statement unless your program is already connected to a MySQL server.
With respect, your "task which states to create a server at runtime" doesn't make much sense. Is there more to this requirement? What workflow needs this step? Is it part of the installation of some application software on a new box?

MySQL to Oracle DB Migration

I have a task to Migrate MySQL DB to Oracle (its my requirement) i tried to Migrate using SQL developer as defined in below link.
https://www.packtpub.com/books/content/migrating-mysql-table-using-oracle-sql-developer-15
As the DB is huge, the constraints are not copied properly from MySQL to Oracle, i need to define/alter/add constraints explicitly, which is time consuming (SQL developer migrates data 300rec/min from mysql to Oracle) & the entire procedure, views, functions is need to re write.
How can i ensure that data has migrated properly or not.?
Is this is a right approach to migrate?
Should i move to any tool which helps to Migrate? If yes please suggest the tool..!!
Or it is the right thing to Move from MySQL to Oracle.
Thanks in Advance.
No specific answer, but some genaral thoughts based on my experiences with migration.
I've found that there normally isn't one tool that does the whole migration job well, and by whole job I mean:
Fast
Handles all data types, scenarios
And that is from Oracle to Oracle!!
Last project we tried Oracle Golden Gate, and found there were issues with that.
We always end up with a hybrid approach, somethings like:
Extract all DDL manually and pre-create objects - there are weaknesses in the stagndard tools that confound them when extracting DDL, e.g. we found 10g expdp did not handle some quirky PLSQL well, so we resorted to extracting this ourselves.
Some tables work well with SQL Loader, others with GG, others (rare) with a custom extract and load process. We had over 3,500 tables and identified about 100 that worked better done as SQLLoader rather than GG. When I say better I mean with data handling and speed of migration. We created different groups of processing each group having a different method.
Once we have an overall hybrid scheme that works, we tune, mainly by splitting that task into parallel processes, both the export and import side.
All my migrations have been big projects where we have shifted from one Oracle system/server to another, always with the target being a newer version of OS and Oracle.
So, I would imagine that migration between non-Oracle and Oracle will through up even more challenges, and probably not as trivial as imply clicking a few buttons in SQL*Developer.
You may find the expected content from the SQL developer documentation at the Oracle website.
There are migration information available for all Microsoft Access users, MySQL users, Microsoft SQL Server and Sybase Adaptive Server users.
You can also download the tutorial in forms of PDF (best for offline viewing and printing), ePub (best for most mobile devices) and Mobi (best for Amazon Kindle devices).
Recently, I have successfully migrated the MySQL database to Oracle database. Below are detail steps:
Operating System: Desktop Ubuntu local and Desktop Ubuntu on amazon aws
Please Note: Here I am using aws desktop ubuntu server because my mysql
database was pretty big. In my case there were 800 tables, 200 views,
procedures, triggers, and functions. The total size of the database was almost
20GB. In case of small database I would recommend to use local ubuntu server.
Tools Used: SQL Developer, VNCServer, Remote Desktop Client, JAVA 8, Third Party MySql JDBC Driver
1. Setup ec2 ubuntu desktop server : https://www.youtube.com/watch?v=ljvgwmJCUjw
2. Install SQL Developer on #1
Download the SQL Developer package from this link :
http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html
Accept the license agreement and download "Other Platforms" for ubuntu.
Install the SQL developer package as the following.
sudo apt-get install sqldeveloper-package debhelper openjdk-7-jdk
openjdk-7-jre icedtea-7-plugin
Now all that you need to do is to run the command (you might have a
different version)
make-sqldeveloper-package sqldeveloper-4.1.3.20.78-no-jre.zip
This will generate a debian package that you can use to install SQL developer.
Now install the resulting .deb package using the command (Your deb
might have a different version too)
sudo dpkg -i sqldeveloper_4.1.3.20.78+0.2.4-1_all.deb
In my case, I have used java 8.
3. Once you have done with your SQL developer installation on your newly created ec2 instance with VNCServer then all you need to do is to connect to that ec2 instance with the Remote Desktop Client by default available in your ubuntu local machine.
Use IP:1 with user/pass setup for VNCServer in #1
You can see the remote ec2 ubuntu desktop server. You have to grab the keyboard inputs from the Remote Desktop tool if you want to tab inside the remote server.
Once you get connected with the remote client, open SQL Developer from the terminal or from the explorer.
sqldeveloper
Follow the migration steps provided by Oracle corporation:
http://www.oracle.com/technetwork/database/migration/mysql-093223.html
Please Note: While following the migration steps provided by the
oracle they will ask for the destination database connection i.e. oracle
database connection. This is not the database where your MySQL
database will be migrated. Instead, this database connection will
be used for the migration process. Your database connection user
must have user and database create privileges. Once your connection
have user create privilege, then migration process automatically create
the corresponding database user in Oracle database[if you have mysql_test_db in MySQL
database, same mysql_test_db will be created in Oracle db too].
I recently used sqline's tool http://www.sqlines.com/cmd to convert a dump from mysql in the form of an .sql script to an (almost) Oracle-compatible sql script.
sqlines31113\sqlines.exe -s=mysql -t=oracle "-in=$infile"
I just had to (semi-manually) fix some things in the output and then I could run it on my oracle database.

How to convert '.bak' file into '.sql' file in order to import the database in MySQL phpMyAdmin?

I'm a PHP developer by profession. I'm using Ubuntu Linux on my machine.
I don't have any idea about .Net framework and MS SQL Server Express database.
I've received a file titled project_db.bak and I have to convert it into project_db.sql in order to import the same database into MySQL.
I searched over the Internet for the solution. I found couple of answers but they are asking to use MS SQL server tools which I can not. I have to achieve this conversion in some other way.
Can someone please help me in this regard?
MS Sql Server typically generates binary backups, so what you have I guess is a backup. To restore it to a "querable" state you will need MS tools or RESTORE statment someway executed against the Motor (that you will need). Once it was "restored" (that is the reverse to a MS backup) you can dump (in MySql terms) with a tool or with a script
Create a Virtual Machine Windows 7 or better.
In the VM make sure you have a second network card that's set to a private network with your Host so you can connect to your Host MySQL you will need a User in your MySQL Server setup that allows connections from your remote network
in this VM install SQL Server, and SQL Server Management Studio & Navicat from that you can then restore the .bak file, once you have it restored. you will need another external tool that allows you to export as another format for this i use Navicat export is as another format. you can then connect to your MySQL Server and import that exported file.

How can I migrate my MsSQL database on a hosted website to a MySQL database on a different hosted website?

I have a MsSQL 2008 database hosted on somee.com . I have purchased another hosting under net4.in which is providing me MySQL database. So now, how can I migrate/synchronise my MsSQL database to the MySQL database ?
I have tried below things but in vain :
There is an inbuilt facility provided in the MySQL in net4.in to synchronise two databases on remote servers,where I have tried selecting the target server as "Current Server" and in Source Server, I have selected "Remote Server" and provided connection details which were available to me from somee.com . Unfortunately, the Socket and Port details are not provided on somee.com, I have tried giving various values like "TCP/IP" and "1433"(the default value) but in vain.
There is an import facility in MySQL in net4.in , in which I have given the format of imported file as "SQL" and SQL compatibility mode as "MSSQL" , but it is giving an error showing some encrypted text from my MSSQL database saying that its not able to understand it.
The easiest way is to export a csv or .sql file of your existing database then import it using our web-based DB management tools at http://db.infuseweb.com.
However, this may not always be effective especially if you have very large database files. In which case you will need to submit a support ticket and provide us with a MSSQL .bak file or all the MySQL database files from your old host. You will also need to create an empty database in Helm with the exact same database name and users/passwords that you have with your old host. We will then move the database under your account.

TeamCity won't create its schema in SQL Server

I've installed a new TeamCity instance and just moved from internal storage to database (SQL Server). Followed the instructions at http://confluence.jetbrains.com/display/TCD7/Setting+up+an+External+Database and I know I've done the database part correctly as it wouldn't initially connect and I had to go back and turn on TCP/IP connections for SQL Server.
From the documentation I assumed that team city would create and maintain it's own database schema, but even though it's user is dbo the database remains blank - no tables, views or any other objects have been created.
When I try to connect to it in a browser I get "Database is empty or doesn't exist", and viewing the logs shows me "Schema contains no tables". I've obviously restarted the service and connected again each time.
Is there an install script I am missing? How do I get TeamCity to install it's schema?
When you are doing it like this, you will need to migrate the initial structure over to sql server. See here