I'm building two applications which will share some data in common schema. I'm using MySQL as RDBMS. Here is my first schema (test_schema_1
):
And second (test_schema_2
):
I recently learned that I can do JOINs between multiple schemas. When I'm connected with root user (unlimited access to everything), I do:
SELECT * FROM TEST_SCHEMA_2.USERS U JOIN TEST_SCHEMA_1.MASTER_USERS MU ON U.MASTER_ID = MU.ID JOIN TEST_SCHEMA_2.ROLES R ON U.ROLE_ID = R.ID WHERE MU.APP_ID = 'darth_vader@death.star';
And get what I expect! This looks very cool for me, as I'm thinking of going to production with this design.
But I'm a bit afraid of performance implications of such design? Is this a good idea? What if in future I decide to shard (in MongoDB terminology) the database on different machines?
Also, I'm wondering of security problems. Currently, I have a separate user for each schema:
Host Db User Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Grant_priv References_priv Index_priv Alter_priv Create_tmp_table_priv Lock_tables_priv Create_view_priv Show_view_priv Create_routine_priv Alter_routine_priv Execute_priv Event_priv Trigger_priv % test_schema_1 t1 Y Y Y Y N N N N N N N N N N N N N N Y localhost test_schema_1 t1 Y Y Y Y N N N N N N N N N N N N N N Y % test_schema_2 t2 Y Y Y Y N N N N N N N N N N N N N N Y localhost test_schema_2 t2 Y Y Y Y N N N N N N N N N N N N N N Y
So I expect that user t1
cannot read from test_schema_2
. But the query above works. He even can insert in test_schema_2
:
SELECT USER(); INSERT INTO TEST_SCHEMA_2.ROLES(ID, NAME) VALUES(4, 'TEST'); ... USER() t1@localhost ------------------------------------------- Updated Rows 1
What am I missing?