Is there a suggested way to use "schemas" in mysql? For example, if I have one database called events and then I want to have two environments dev and prod, what might be a way to do that? Currently I add a table prefix, but it seems a a bit hack-ish:
you create a separate database for that, because MySQL does not have the concept of schema like e.g. PostgreSQL does.
You create one database for production e.g. prod_database with the table names event and event_type. and one database for dev e.g. dev_database, with the same table names event and event_type. As you always want to have the same table names in different environments.
You could (and should) even use the same database name, if you host the database on different servers. Which for production and development/staging would also make sense e.g. to test server version updates on one setup without affecting production.
What is the difference between database schema and database structure?
I am learning dbms and these two words are confusing for me. Dint find much information anywhere else.
Database schema and database structure can be used interchangeably, more or less. Most software developers will understand them to mean the same thing.
Schema in particular is used in two different ways:
A schema is like a folder that contains tables. You use statements like CREATE SCHEMA <schemaname>, DROP SCHEMA <schemaname>, USE <schemaname>. In MySQL, SCHEMA and DATABASE are synonyms in most contexts.
A schema is sometimes used to refer to the full definition of all objects in your project, including the schema, tables, indexes, procedures, functions, etc.
Does a database relationship need to be established before you can impliment a INNERJOIN In a PHP Query?
Furthermore, when I export my Database via PMA; My already created relationships to not get exported. So I'm having to re-create my relationships apun every import.
Is it possible to export with the relationships?
No. The relationship is preferred when being optimized, but a relationship is not required to use a JOIN.
When exporting your database, make sure you use the Custom - display all possible options method. You may missing an option that is not including those constraints. Another possible reason is if you're not using InnoDb as the table engine, otherwise those constraints are discarded with MyISAM. See this question for more info.
Is there a difference between a schema and a database in MySQL? In SQL Server, a database is a higher level container in relation to a schema.
I read that Create Schema and Create Database do essentially the same thing in MySQL, which leads me to believe that schemas and databases are different words for the same objects.
As defined in the MySQL Glossary:
In MySQL, physically, a schema is synonymous with a database. You can substitute the keyword SCHEMA instead of DATABASE in MySQL SQL syntax, for example using CREATE SCHEMA instead of CREATE DATABASE.
Some other database products draw a distinction. For example, in the Oracle Database product, a schema represents only a part of a database: the tables and other objects owned by a single user.
Depends on the database server. MySQL doesn't care, its basically the same thing.
Oracle, DB2, and other enterprise level database solutions make a distinction. Usually a schema is a collection of tables and a Database is a collection of schemas.
Refering to MySql documentation,
CREATE DATABASE creates a database with the given name. To use this
statement, you need the CREATE privilege for the database. CREATE
SCHEMA is a synonym for CREATE DATABASE as of MySQL 5.0.2.
PostgreSQL supports schemas, which is a subset of a database:
https://www.postgresql.org/docs/current/static/ddl-schemas.html
A database contains one or more named schemas, which in turn contain
tables. Schemas also contain other kinds of named objects, including
data types, functions, and operators. The same object name can be used
in different schemas without conflict; for example, both schema1 and
myschema can contain tables named mytable. Unlike databases, schemas
are not rigidly separated: a user can access objects in any of the
schemas in the database they are connected to, if they have privileges
to do so.
Schemas are analogous to directories at the operating system level, except that schemas cannot be nested.
In my humble opinion, MySQL is not a reference database. You should never quote MySQL for an explanation. MySQL implements non-standard SQL and sometimes claims features that it does not support. For example, in MySQL, CREATE schema will only create a DATABASE. It is truely misleading users.
This kind of vocabulary is called "MySQLism" by DBAs.
in MySQL schema is synonym of database.
Its quite confusing for beginner people who jump to MySQL and very first day find the word schema, so guys nothing to worry as both are same.
When you are starting MySQL for the first time you need to create a database (like any other database system) to work with so you can CREATE SCHEMA which is nothing but CREATE DATABASE
In some other database system schema represents a part of database or a collection of Tables, and collection of schema is a database.
Yes, people use these terms interchangeably with regard to MySQL. Though oftentimes you will hear people inappropriately refer to the entire database server as the database.
Simply if you are thinking or discussing about Mysql. Then take a simple answer
"SCHEMA & DATABASE are exactly the same thing, just a synthetic
sugar in mysql."
Just add some more info:
MongoDB also distinguish schema from database.
schema represent the tables, which means the structure of database.
Microsoft SQL Server for instance, Schemas refer to a single user and is another level of a container in the order of indicating the server, database, schema, tables, and objects.
For example, when you are intending to update dbo.table_a and the syntax isn't full qualified such as
UPDATE table.a the DBMS can't decide to use the intended table. Essentially by default the DBMS will utilize myuser.table_a
not like Postgres, SQL server schema is set of database have same thing
but in mysql schema and database it is the same
MySQL does not support the concept of schema. In MySQL, schema and schemas are synonyms for database and databases.
When a user connects to MySQL, they don't connect to a specific database. Instead, they can access any table they have permissions for
After dragging two tables in from one database, I switch to another and drag a table in. Now I get a message if I want to replace the connection string with the new one. I want tables from multiple databases in one DBML. Is this possible?
It is entirely possible to reference multiple databases within the same DBML, PROVIDED those databases reside on the same SQL Server.
In Visual Studio, right-click on the DBML, click "Open with..." , and select XML (Text) Editor with Encoding.
You will see your first table that you dragged in looks like this:
<Table Name="dbo.MyTable1fromMyDatabase1" Member="MyTable1fromMyDatabase1">
For your tables from other databases you wish to add, enter them like this:
<Table Name="MyDatabase2.dbo.MyTable1fromMyDatabase2" Member="MyTable1fromMyDatabase2">
This will work assuming the same login works for both databases, and your LINQ expressions can now query across both databases!
I don't believe that what you're looking for is possible, since the DataContext would then not have any easy way of resolving results from two separate databases.
If you're looking to create domain objects from two separate databases, then your best bet would be to have two separate DBML's, then use a bridge (GOF) or some other related design pattern to instantiate your domain objects.
Another option is to create a server link on on database that points to the other and make aliases to the remote tables from the "local" DB. I believe then you'd be able to reference them as if they were all in the same database.
We can also create a view that queries the table in the other database. We can select, insert and update this view, which will affect the table in the other database as well.