How to use MySql Memory Storage Engine in Hibernate? - mysql

Is there any way to tell Hibernate use MySql Memory Storage Engine?
Thanks.
Edit: I found Memory Storage Engine does not support all features of a regular Store Engine like InnoDB, etc. So it may be seemed logical that there is no option for it.

There should be a properties file where you can put your URL to MySQL
#hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
#hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
#hibernate.connection.driver_class com.mysql.jdbc.Driver
#hibernate.connection.url jdbc:mysql:///mysqlURL
#hibernate.connection.username
#hibernate.connection.password
But be aware of this
When using the MyISAM storage engine, MySQL uses extremely fast table locking that allows multiple
readers or a single writer. The biggest problem with this storage engine occurs when you have a steady
stream of mixed updates and slow selects on a single table. If this is a problem for certain tables, you can
use another storage engine for them.

The storage engine used by mySQL is declared when you create your tables. Use the qualifier ENGINE=MEMORY at the end of your CREATE TABLE DDL. Then use it like any other table.
But, of course, remember that if your mySQL server bounces for any reason, all rows will be gone from that MEMORY table when it comes back.

Why do you want in-memory storage?
My personal use case scenario for such a setup is testing.
Think about using h2, hsql or derby. AFAIK they all provide in-memory storage. And if you consistently use Hibernate, it should make no difference which database runs in the background -- at least not from a development standpoint.

Related

Is it safe to turn INNODB engine on when all the tables are MYISAM at the moment?

I need to have possibility to make transactions while using one of my mySQL tables.
I could do that if I'd switch engine from MYISAM (which is set by default to all of the tables at the moment) to INNODB.
However I am not MySQL server admin and guy who is has asked me if I have read about possible dangers of doing so.
I tried to find an answer and failed, so here's my question:
INNODB is currently DISABLED (it says so when im execute SHOW ENGINES). Can I turn it ON without risk of damaging any data in existing MYISAM tables? Are there any specific dangers when doing so?
MYSQL version of server is 5.09.
No, there is no danger to making another engine available for database and object creation in MySQL. You will have to stop and restart your MySQL service for it to take effect, so you'll have a modicum of downtime, so do it after business hours.

Concerns Of Using Mixed MyISAM & InnoDB On AWS RDS

I am really new to AWS and I want to migrate my database to AWS RDS. But I'm facing several issues. The database is entirely built using MyISAM instead of InnoDB. From what I read at AWS RDS documentation, I understand that I can enjoy the AWS RDS features if I use InnoDB for the database, e.g. the daily backup and the read replica.
The main reason I use MyISAM is to utilize the Full-Text Search and the Spatial Indexing. Until this day, I understand that the MySQL version supported by AWS RDS still doesn't support Full-Text Search (According to this, it's for 5.6.4) and the InnoDB still doesn't support Spatial Indexing too.
So here are my questions
Let's say I convert all remaining tables that don't need the FTS & Spatial to use the InnoDB engine, how optimal can I use the features provided by AWS RDS (read replica, daily backup, etc)?
Will it be any better if I break down a table into two table, one in InnoDB and one in MyISAM? This concern came because some of the columns are often be updated, so those columns will be moved to the InnoDB one to avoid table locking. On the other hand, the MyISAM one is rarely updated.
Let's say I use separate engine for the Full Text e.g. Sphinx or Solr, how can I use it along with RDS? And is there a separate engine for Spatial Indexing that can be used along with RDS?
Any better idea?
The reason for this is that MyISAM is not considered ACID compliant. This means if that something were to happen to your database in the middle of a transaction, it could be left in an inconsistent state.
Personally, I would use full text search engine designed for the purpose. The quality of results is generally much better than what mysql provides and you can offload some of the work from your mysql server.

Life without transactions (MyISAM)

My site runs on a VDS-server. I've just found out that my MySQL server doesn't support InnoDB engine, therefore I can't use database transactions in my application.
It makes me think, that some people might never use transactions. Is this the case? If so, how does one manage to coordinate related operations on different tables in MyISAM?
Otherwise, is there a way to install InnoDB on a MySQL server which is run on a VDS?
Thanks!
If you need transactions, then you need transactions and MyISAM isn't going to cut the mustard.
Some applications won't need transactions. For example; an application that never runs more than one related SQL statement at a time and has no need to rollback multiple SQL statements. Another example is an application that uses MySQL as a simple Key-Value Store. There are many use cases that don't require database level transaction support.
It's hard to answer the second part of your question without knowing more details about your VDS. Who is you hosting provider? Do you have shell access and permissions to change my.cnf? If not, then you probably won't be able to enable InnoDB. If you do, then here is a another SO answer that details how to enable InnoDB on MySQL: How to enable INNODB in mysql
You can often either enable the engine, install the InnoDB components manually, or simply re-install a version of MySQL that includes that engine by default. MyISAM is the crazypants database, stupidly fast but also unreliable and prone to complete destruction if your system isn't shut down properly.
Running a mission critical application on MyISAM is an extremely bad idea. Where you need MyISAM tables for performance reasons they should always be disposable, easily re-built from another more reliable source of data.

Is innodb required/recommended for Spring Security?

I have a grails app that uses the Spring-Security-Core plugin, which integrates Spring Security 3 into my app. I belive that Spring/Hibernate will do some transactional operations under the hood. If that is the case, would it be better to use mysql's innodb engine instead of the default MyIsam engine? or are the operations independent of the underlying database?
Thanks in advance!
There's nothing particularly transactional about how the plugin works. It only reads - the primary database access will be loading a user and the user's assigned roles. You will want to use transactions when updating the user, assigning roles, etc. but that has nothing to do with security, it's just the right thing to do.
As the others said, there's very little reason to use MyISAM except in specialized use cases that are probably better suited for a NoSQL database. InnoDB is very fast and has excellent transaction support.
InnoDB enforces referential integrity; MyISAM does not.
Looks like MyISAM does not support transactions/rollback:
http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-transactions.html
So if a transaction manager is required, better to go with InnoDB.
Actually i think innodb engine will be wise choice. Main reason - durability and data integrity support. MyIsam more "fragile". Only reason to use it now- huge insert activity - and this is not your case( i try to not go too deep in it- it more complex and don't connected with question).

Which database for a web crawler, and how do I use MySQL in a distributed environment?

Which database engine should I use for a web crawler, InnoDB or MYiSAM? I have two PC's, each with 1TB hard drives. If one fills up, I'd like for it to save to the other PC automatically, but reads should go to the correct PC; how do I do that?
As for the first part of your question, it rather depends on you precise implementation. If you are going to have a single crawler limited by network bandwidth, then MYiSAM can be quicker. If you are using multiple crawlers then InnoDB will give you advantages such as transactions which may help.
AFAIK MySQL doesn't support the hardware configuration you are suggesting. If you need large storage you may wan tot look at MySQL Cluster.
MyISAM is the first choice, because you will have write only operations and crawlers -- even run in parallel -- will be configured -- I suppose -- to crawl different domains/urls. So you do not need to take care of access conflicts.
When writing a lot of data, especially text!, to Mysql avoid transactions, indexes, etc., because it will slow down MySQL drastically.