Trying to create MySql DB with Nhibernate - need some direction - mysql

So I am very new to web development and working on a new project that will make use of Nhibernate as my ORM and MySql database.
I wanted to set it up so that NHibernate would create my database table based on the (all necessary NHibernate files). So far I have concluded that NHibernate will generate the DB schema that I have laid out with the mappings and class files.
The problem I am seeing is that it appears that you must have the database in place in MySql first for NHibernate to create the table (understood). However, when reviewing creating a MySql database in the manual it is requiring you to specify the schema with the create command.
So far the number of blogs I have read concentrate on what you need for NHibernate and not much details in correctly prepping your MySql server.
Any direction or advise is greatly appreciated.

You need to run the "create database [databasename];" command before building up your schema. You don't neeed to specify a schema to use this command.

Related

Liquibase create schema for MySQL

Is there any way to create schema through liquibase script ?
After some research I've found out that we need to include a create schema in change log file.
I'm thinking on similar terms for question asked previously for postgres
Any pointers or help is welcomed.
Found an answer that was mentioned already on stackoverflow.
We can create a fresh database using this URL.
jdbc:mysql://localhost:3306/database_name?createDatabaseIfNotExist=true
createDatabaseIfNotExist this keyword create a fresh new database in your system. If the database does not exist. if exist, skip executing.
Your proposed solution to your own question is to separate stuff by database, while your original question was about how to separate stuff using schema. Those are not the same.
If you are using Liquibase in "embedded mode", meaning it is your application code which controls Liquibase execution, not some Maven cmd or Liquibase CLI, then you can have a look at Pre-Liquibase.
Pre-Liquibase attempts to solve the chicken-and-egg problem inherent to Liquibase: It cannot be used to setup its own "home" (Liquibase needs two tables of its own that has to live somewhere), nor can Liquibase ChangeSets be used to create databases or schemas.
This is the problem which Pre-Liquibase solves. It executes some SQL prior to Liquibase itself. For example, you can use it with MySQL to make sure the database exists without fiddling with URL. In such case your Pre-Liquibase SQL script file would look like this:
CREATE DATABASE IF NOT EXISTS my_database_name
You can use Pre-Liquibase if you are using Spring Boot or just Spring Framework without Spring Boot. However, feel free to steal the ideas if you have another tech stack.
(full disclosure: I'm the author of Pre-Libuibase)

Data migration tool for mysql in new upgraded application with deferrent schema and table structure

We are migrating our existing code base to a new robust code base for better performance and reliability. We have a MySQL database with current data. Now we have modified our entities in our spring boot application which will change our schema for the new database structure. I am in search of a tool which will help me migrate all the data from the old MySQL database to a newly created MySQL database with changes according to the latest schema design. I think I will have to write some code to match the new database architecture as no tool will do that refactoring according to my requirement. What tool should be helpful to achieve this?
Footnotes:
I am working in a microservice architecture.
I have integrated liquibase with maven plugin support.
I have seen Apache Spark and ETL, but they need
Provide your feedback if you have any relative experience.
We have done the migration of near about 3000 users data from 160(SQL) to near about 75 tables (MySQL) as per new schema.
As per our experience, I can suggest following things -
1. Prepare mapping sheet of the column in the table to table manner.
2. Migrate them into temporary tables.
3. Test the temporary table's data with the old one. Compare data of each table column by column. You can use ETL tool or excel for comparison.
4. Then write down sp or script for actual migration if no bugs found.

Migration from MySQL to Postgresql with auto-increments - how?

I'm considering a MySQL to Postgresql migration for my web application, but I'm having a really hard time converting my existing MySQL database to Postgresql.
I tried :
mysldump with --compatible=postgresql
migration wizard from EnterpriseDB
Postgresql Data Wizard from EMS
DBConvert from DMSoft
and NONE of the above programs do a good job converting my database!
I saw some Perl and Python scripts for converting mysql to postgresql, but I can't figure out how to use them....(I installed ActivePerl and don't understand what I'm supposed to do next to run that script!)
I use Auto Increment fields (as a primary key) all the time, and these are just ignored... I understand that Postgresql does auto-increments in another way (with sequences), but it can't be THAT hard for MIGRATION software to implement that, or is it?
Did anybody have better luck converting a MySQL database with auto-increments as primary keys?
I know this is probably not the answer you are looking for, but: I don't believe in "automated" migration tools.
Take your existing SQL Scripts that create your database schema, do a search and replace for the necessary data types (autonumber maps to serial which does all the sequence handling automagically for you), remove all the "engine=" stuff and then run the new script against Postgres.
Dump the old database into flat files and import them into the target.
I have done this several times with sample databases that were intended for MySQL and it really doesn't take that long.
Probably just as long as trying all the different "automated" tools.
Why not use an ETL Tool? you dont have to worry about dumps or stuff like that.
I have migrated to PostgresSQL and MySQL and have had no problems with the auto increment fields.
You just need to know the connection credentials and thats it. I personally use Pentaho ( it's open source ).
Download Pentaho ETL from http://kettle.pentaho.org/
Unzip and run Pentaho (using .bat file spoon.bat)
Create a new Job:
Create DB connection for source data base (PostgreSQL) - using menu: Tools→Wizard→Create DataBase Connection (F3) Create DB connection for destination data base (Mysql) - using technique described above.
Run the Wizard: Tools → Wizard → Copy Tables (Ctrl-F10).
Select source (left dialog panel), and destination (left dialog panel). Click Finish.
The Job will be generated - Run the job.
If you need any help let me know.
Even when you familiar with all "PostgreSQL gotchas", doing every step by hand may take a lot of time, especially when your db is "big".
Try some other scripts/tools.
I know this is an old question but I just ran into the same problem migrating from MySQL to Postgres. After trying several migration tools out the very best one I could find, which will migrate your database structure as cleanly as possible, was Pgloader https://github.com/dimitri/pgloader/ it will take care of changing the Auto Increment to Postgres sequences no problem and it's super fast.

How I do to "migrate" the structure from aspnetdb.mdf to a mysql database

I'm creating a new Asp.Net MVC 3 application. Visual Studio does a lot of the job of create the database and initial layout. Very nice! I will upload that initial files to my server, but I want that it runs using the MySql database on the server.
There's some quick/easy way to do it? I'm not worried about the data, just the structure of the tables, and the connection/configuration changes.
Thank you very much!
You can export any MS-SQL database as a Script (Sql Server manager).
Fix it up to make it compatible.
But you will also need a Membership provider, look around if there exist any for MySql, otherwise you'll have to create one (movie).
There are a number of tools listed in "Migrating from Microsoft SQL Server and Access to MySQL".
Or (assuming that you're using column types that exist on both platforms) you can write a script to convert a schema dump from SqlServer into MySQL (or do the conversion by hand in a text editor). Even better yet, you can write a program program to read the INFORMATION_SCHEMA table from SqlServer and produce the necessary CREATE TABLE... statements in mysql. Lots of options.

Migrate Grail's HSQLDB embedded database

how to migrate Grail's HSQLDB embedded database(That contains my App's Data that I don't want to lose) into external one, such as MySQL or ApacheDerby?
If your data isn't important just let hibernate regenerate your schema, else try this: http://www.grails.org/plugin/liquibase
The MySQL Migration Toolkit may be exactly what you need.
A little searching turned up this article that shows examples of what the GUI Tool looks like.
I haven't had to migrate data from a HSQLDB to any other DB, but if I had data that I didn't want to use in a HSQLDB then I'd definitely try this method.
You are going to want to backup the
HSQLDB database that you want to save
(I'm assuming you used a file DB
rather than an in-memory one right?)
Change your DataSource to a MySQL
datasource with the dbCreate set to
update (or something non-destructive)
Run the Migration Toolkit and migrate
your data
Otherwise you ought to be able to view the data in your DB by using another tool (DBVisualizer, RazorDB, or others) and they might be able to help you export the data.
Because grails uses hibernate underneath, no migration is necessary. All you need to do is repoint your conf\DataSources.groovy to the new database, and next time you startup, it will create tables in the new DB.
See section 3.3 in this doc for more information on MySQL config.