Spring boot hibernate change engine from MyISAM to InnoDB - spring

I'm trying to create a ER Diagram from mysqldump file by reverse engineer,
everything works but relationship connections wont show in Workbench.
Note on Workbench:
Foreign keys can only be defined for certain storage engines (like InnoDB).
mysql> SELECT TABLE_NAME,
-> ENGINE
-> FROM information_schema.TABLES
-> WHERE TABLE_SCHEMA = 'db_example';
+--------------------+--------+
| TABLE_NAME | ENGINE |
+--------------------+--------+
| difficulty | MyISAM |
| durations | MyISAM |
+--------------------+--------+
what i've tried:
application.properties
hibernate.dialect.storage_engine=innodb
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
So i'm trying to change the engine to InnoDB but keeps recreating the database as MyISAM

Related

How do I delete all rows of a database table using NiFi Processor? [duplicate]

I have a table that consists of 2 columns
cattlegendernm | price
----------------+-------
Female | 10094
Female | 12001
Male | 12704
I would like to add another column with filename to this table using a nifi processor.
Which Processor and SQL query should I use for this ?
Using a PutSQL processor would be suitable to add such a DDL statement like
ALTER TABLE T ADD COLUMN filename VARCHAR(150)
into the SQL Statement attribute of the properties tab as illustrated below
where PostGRES_DB represents a pre-configured Controller Service to interact with the database

How can I check the database of a table?

I have a table name SOME_TABLE but I don't know the databse it belongs to.
How do I check it?
I suppose, it's impossible to do it from Hive level, cause you need to select database first...
Pawel
Query the metastore directly
Demo
Hive
create table SOME_TABLE (i int);
Metastore (MySQL)
use metastore;
select d.name
from TBLS as t
join DBS as d
on d.DB_ID =
t.DB_ID
where t.TBL_NAME = 'some_table'
;
+----------+
| name |
+----------+
| local_db |
+----------+
You can use the Hive command SHOW DATABASES; to list all databases and then use the SHOW TABLES IN database_name LIKE 'table_name'; command to to see if the table exist in the database.

Grant create external table in Sentry

I have a 4 node cloudera cluster with kerberos enabled on it with sentry securing Hive service.
When i am create a table using hive user i am able to do so as it have all privileges on database default.
0: jdbc:hive2://clnode4:10000/default> create table t123 (a int);
No rows affected (0.204 seconds)
0: jdbc:hive2://clnode4:10000/default> show tables from default;
+--------------+--+
| tab_name |
+--------------+--+
| t1 |
| t12 |
| t123 |
+--------------+--+
3 rows selected (0.392 seconds)
But when i am trying to create a external table on same env with same user hive i am getting error as below
0: jdbc:hive2://clnode4:10000/default> create external table t1_ex (a string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LOCATION 'hdfs:///user/olap/KyvosDemo/Distance.csv';
Error: Error while compiling statement: FAILED: SemanticException No valid privileges
User hive does not have privileges for CREATETABLE (state=42000,code=40000)
I have provided all access on URI as well from were i am reading the data for external table.
Is there any way to provide create external table to user in sentry any help would be great.
I am able to solve the problem by granting all privileges on the server to hive user as below
grant all on server server1 to role hive;
role hive is assigned to hive user.
Edit
More help on this one can find the server name in hive configuration with the property name "hive.sentry.server"

Difference between materialised view and table which is refreshed incremental

There is question that why we create materialised view. I have a table and to refresh the table incrementally I have dbms job which merges the data from different table into this. So it is equivalent to materialised view with fast refresh. Is there any difference? Which implementation is better in above two cases?
Materialized view can be refreshed on demand or on refresh frequency. It can consist of a join of two or more tables.
When creating a materialized view, you have the option of specifying whether the refresh occurs ON DEMAND or ON COMMIT. In the case of ON COMMIT, the materialized view is changed every time a transaction commits, thus ensuring that the materialized view always contains the latest data. Alternatively, you can control the time when refresh of the materialized views occurs by specifying ON DEMAND. In the case of ON DEMAND materialized views, the refresh can be performed with refresh methods provided in either the DBMS_SYNC_REFRESH or the DBMS_MVIEW packages:
Here's the documentation link
Also materialized views can be refreshed incrementally.
Your Custom Solution
Takes a lot of code and does not scale well.
Materialized views following certain conventions can be fast refreshed using a materialized view log. That means Oracle will only have to process actual changes in order to refresh the materialized view, where a merge operation would have to compare all rows every time. Therefore a materialized view would allow for much faster and more frequent refreshes especially with larger tables.
After lot of search I got something on materialised view which we can not do on normal table and it is query rewrite. Below is my finding.
SQL> GRANT GLOBAL QUERY REWRITE to mydbdba;
SQL> CREATE MATERIALIZED VIEW customers_mw ENABLE QUERY REWRITE
AS
SELECT COUNT(*) c,state_id FROM sg.customers GROUP BY state_id;
SQL> alter session set QUERY_REWRITE_ENABLED=TRUE;
Session altered.
SQL> SELECT COUNT(*) c,state_id FROM sg.customers GROUP BY state_id;
Execution Plan
Plan hash value: 799451518
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 52 | 364 | 3 (0)| 00:00:01 |
| 1 | MAT_VIEW REWRITE ACCESS FULL| CUSTOMERS_MW | 52 | 364 | 3 (0)| 00:00:01 |
SQL> alter session set QUERY_REWRITE_ENABLED=FALSE;
Session altered.
SQL> SELECT COUNT(*) c,state_id FROM sg.customers GROUP BY state_id;
Execution Plan
Plan hash value: 1577413243
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 52 | 156 | 327 (1)| 00:00:01 |
| 1 | HASH GROUP BY | | 52 | 156 | 327 (1)| 00:00:01 |
| 2 | TABLE ACCESS FULL| CUSTOMERS | 50000 | 146K| 326 (1)| 00:00:01 |
you can see in above example how a materialised view is used instead of scanning whole table again.

Best Way to Start database from particular number(id) + rails

Rails app + mysql db. I want to start the db on production from a particular id, what is the best way to do it.
The first that is coming to my mind is seeding. Is there any better way I am missing here?
Under Mysql2 in a rails app there's a database called 'information_schema' and it has a table called 'tables' and it has a record where the column table_schema is the name of your sql database and the column table_name is the name of your model's table. The column auto_increment is the next record number to use.
so (for example) for database "my_database" for model table "posts" to set that to start at 500 you would do the following SQL command...
UPDATE information_schema.tables SET auto_increment = 500 WHERE table_schema = 'my_database' AND table_name = 'posts';

Resources