Relational databases that do or don't have a schema/namespace layer - relational-database

In a database system such as MySQL, there is no 'Schema' layer between the Database and table, so the hierarchical layout looks something like this:
Cluster (MySQL):
Database1
Table1
Table2
Database2
Table1
Table2
However in something like Postgres it contains three levels:
Cluster (Postgres):
Database1
Schema1
Table1
Table2
Schema2
Table1
Table2
Database2
...
Is there a listing or comparison of the structure of common relational database engines that show which ones have a two-level hierarchy (such as MySQL) and which ones have a three-level hierarchy (such as Postgres)?

Related

Alter tables on multiple databases from same server

I have multiple databases all having the same table structure on one server.
I need to change three tables in all databases which name is
xx_databasename
where xx is an isoAlpha2Code of the country the database os connected to.
So how can I perform a query like
DROP TABLE IF EXISTS tablename;
CREATE TABLE tablename (....);
on each database with just one mySQL command?

MySQL Replication master - master

I have two servers (A & B), with MySQL Enterprise Edition 5.7.21, and RHEL 7.4 version. I want to replicate one table from Server A with a table with different name to Server B. In same time i want another table from Server B to replicate to an another table to Server A, like two master-slave:
masterA -> SlaveB
masterB -> SlaveA
I know how create replication. My Question is if i can replicate one table to another table name. For Example:
ServerA:
User: myschema
tables: t1, t2
ServerB:
User: myschema
tables: t3, t4
I want to replicate:
myschema.t1 => myschema.t3 (master Server A, Slave Server B) and
myschema.t4 => myschema.t2 (master Server B, Slave Server A)
Is that possible?
I want the result to be the same data in a combination of tables:
--serverA:
select * from t1
union
select * from t2
is equal to
--ServerB:
select * from t3
union
select * from t4.
Info about my.cnf in both servers, for only one replicate.
ServerA:
master
server-id=1
log_bin=/storage/mysql/mysql-repl.log
relay-log=/storage/mysql/mysql-relay-repl.log
binlog_do_db=test
replicate-do-db=test binlog-ignore-db=information_schema
replicate-ignore-db=information_schema auto-increment-increment=2
auto-increment-offset=1
bind-address=10.124.xxx.xx
ServerB:
slave
server-id=2
log_bin=/storage/mysql/mysql-repl.log
binlog_do_db=test
replicate-do-db=test
replicate-do-table=test.t1
binlog-ignore-db=information_schema
replicate-ignore-db=information_schema
auto-increment-increment=2
auto-increment-offset=2
bind-address=10.124.xxx.xx
No it's not possible, you always replicate between tables with the same name because you are replaying the log from one server on it's slave.
Since you seem to be writing to both servers and into different tables, why don't you just have tables t1 and t2 on both and have your application write t1 data to one server and t2 data to the other server and replicate master-master?

difference in data of mysql same tables of different databases

I want to find out the differences of two same structured tables but in different databases,One is master table & i want to sync all other similar tables in different databases with it.
For example t1 table in db1 and t2 table in db2, want to find out difference between t1 & t2 using mysql.

MySql- How to get a list of different tables from two different databases

I am having two mysql databases. One is NEW and other one is OLD.
I require the list of different tables between two databases. That is my old database is having the list of 155 tables and my new database is having the list of 165 tables.
How can I get the name of the TEN differnt tables ?
Is there any tool to do that or we can able to do via query ?
Any help will be thankful...
Thanks in advance..
Have you tried:
SHOW TABLES IN database;
or using information schema:
select table_schema,
table_name from information_schema.tables
where table_name = ???;
EDIT AS PER OP'S COMMENT:
The INFORMATION_SCHEMA database is made up of temporary tables using the MEMORY storage engine.. All tables in the INFORMATION_SCHEMA database are stored directly in memory as MEMORY storage engine tables. They are totally internal to MySQL, so the .frm mechanisms are handled in mysqld. In my answer, I first showed the table layout of INFORMATION_SCHEMA.TABLES. It is a temporary table in memory. It is manipulated using storage engine protocols. Thus, when mysqld is shutdown, all information_schema tables are dropped. When mysqld is started, all information_schema tables are created as TEMPORARY tables and repopulated with metadata for every table in the mysql instance.
For e.g. If your run following two commands you will see all the databases in your mysql metadata.
show databases;
use information_schema; show tables;
Here you are specifying a table_schema to get the table names.
SELECT table_name from
information_schema.tables WHERE table_schema = 'mydb';
With a join: assuming one database name is db1, other db2
SELECT table_name from
db1.tables x
inner join
db2.tables
on x.table_name = y.table_name
;
I think you should query on database information_schema. It's a table which contains all meta data of all database.
Query something like:
SELECT * FROM `TABLES` T1
LEFT JOIN `TABLES` T2
ON T1.`TABLE_NAME` = T2.`TABLE_NAME`
WHERE T1.`TABLE_SCHEMA`='xxx'
AND T2.`TABLE_SCHEMA`='yyy'
AND T1.TABLE_CATALOG IS NULL
You can do this by querying the INFORMATION_SCHEMA (a database which contains information of other databases in the server like table names, column names, primary key columns, primary key names, indexes, etc.) like this:
-- this gives the table names that are in the new table but not in the old table
select newTable.TABLE_NAME
from TABLES newTable
where newTable.TABLE_SCHEMA='NEW' and newTable.TABLE_NAME not in
(
select oldTable.TABLE_NAME
from TABLES oldTable
where oldTable.TABLE_SCHEMA='OLD'
)

MySQL MERGE table across separate databases

I have a database db1 which contains tables tbl1, tbl2, and tbl3.
I also have an empty database db2.
Can I create a MERGE table mrg1 which merges the contents of tbl1, tbl2, and tbl3 from database db1, but is stored in database db2?
Yes, if your database is set up to allow you to run queries against multiple databases at once. I think it would look something like this,
INSERT INTO db2.mrg1 (colA,colB,ColC)
(
SELECT colA,colB,ColC
FROM db1.tbl1,db1.tbl2,db1.tbl3
WHERE [whatever joins your tables together]
)