I have one database in mysql.
But when i log into phpMyAdmin , it shows another database called information_schema.
Is that database always present with one database?
I mean to say is there a copy of information_schema for every database present in mysql or is there one database called inforemation_schema per mysql server?
If i modify this information_schema database how will that affect my current database?
You can think of information_schema as a "master database" that holds details about all the other databases on the server such as the names and types of tables, columns and users.
What is information_schema?
From the reference documentation:
INFORMATION_SCHEMA provides access to
database metadata.
Metadata is data about the data, such
as the name of a database or table,
the data type of a column, or access
privileges. Other terms that sometimes
are used for this information are data
dictionary and system catalog.
INFORMATION_SCHEMA is the information
database, the place that stores
information about all the other
databases that the MySQL server
maintains. Inside INFORMATION_SCHEMA
there are several read-only tables.
They are actually views, not base
tables, so there are no files
associated with them.
What is stored in information_schema?
You can see the kinds of things stored in information_schema, and the way in which they are organised, by viewing this diagram (for MySQL 5.0) or this diagram (for MySQL 5.1).
What happens if I modify information_schema?
In reality, information_schema is a collection of read-only views. As such, it should be impossible to modify it and do any damage. However, the MySQL FAQ on this topic has this to say:
23.7.3: Can I add to or otherwise modify the tables found in the
INFORMATION_SCHEMA database?
No.
Since applications may rely on a
certain standard structure, this
should not be modified. For this
reason, we cannot support bugs or
other issues which result from
modifying INFORMATION_SCHEMA tables or
data.
This implies that if you do find yourself able to modify information_schema (which should be impossible, and is in MySQL, but other vendor implementations of SQL might allow it) you should at the very least choose not to. If you could damage/modify information_schema you'd be damaging the actual structure (e.g. table names, column types) of your other databases.
Does every user have their own copy of information_schema?
Each user can see information_schema that pertains to the tables and databases they have access to. Some users with heavily limited rights will still see information_schema but will see only NULL values for any information_schema queries. However, it is important to remember that information_schema is not an actual database, but simply a convenient way SQL provides so that you can select information about your database(s) and table(s).
From the reference documentation:
Each MySQL user has the right to
access these tables, but can see only
the rows in the tables that correspond
to objects for which the user has the
proper access privileges. In some
cases (for example, the
ROUTINE_DEFINITION column in the
INFORMATION_SCHEMA.ROUTINES table),
users who have insufficient privileges
will see NULL.
Where can I find more information?
The MySQL Reference Manual article on information_schema (http://dev.mysql.com/doc/refman/5.0/en/information-schema.html)
The MySQL FAQ article on information_schema (http://dev.mysql.com/doc/refman/5.0/en/faqs-information-schema.html)
Related
When I access other users' objects, I can do something like
select * from user_2.booking_table;
given that I have the privileges over user_2's objects.
Using the console, I know I can do
alter session set current_schema=user_2;
to avoid prefixing user_2 in front of object's name - so I can do
select * from booking_table;
as if booking_table is my table without specifying user_2 each time.
If I want to bring similar idea to GUI client...
Using Oracle SQL Developer, under each connection, I know I can browse other users' objects under the tree node Other Users > user_2 > Tables/Views/Indexes etc...
Is there anyway I can "import" user_2's objects so that they appear under my Tables, Views, Indexes, etc under the connection, as if they look like they are my objects?
No. We show you what you have, or what other schemas have.
The only way to get close to what you're looking for is if you were to create synonyms to tables in other schemas, then you can ask SQL Developer to present those as TABLES in your connection list.
I'm logged in as a user with an 'empty' schema, at least as far as tables are concenred.
I enable this filter check item, and click 'OK' -
I talk about this in detail here.
Disclaimer: I'm the product manager for Oracle SQL Developer.
Using schemacrawler and trying to connect to an Oracle database. The resulting json file is only including about 10 tables, but we are expecting a much larger number of tables in the database.
This must be restricted by permissions of the user being used to access the Oracle database, but what permissions are required for that user for schemacrawler to be able to "see" the table/columns?
Presumably schemacrawler uses the data dictionary. So the user will be restricted to what tables and columns are visible in ALL_TAB_COLS view i.e. what tables they have at least SELECT privilege on.
Otherwise the user needs select on DBA_TAB_COLS, which shows all tables in all schemas. That requires DBA access to grant.
I installed Oracle on my system, so now orcl is the SID, which is the unique identifier of my database instance.
Now starter db was created as part of the installation. I created 2 users user1 and user2 using the system account.
Using SQL developer I am accessing the users, this shows me 2 different connections with all the database objects like tables, stored procedures views etc.
so
When using these 2 users, am I accessing the same database? I am giving all the ddl commands by logging into the user1 or user 2, does all this data goes into the same .dbf file?
The database instance can be connected to only one database, then does this essentially mean that everytime I create a new database, to make a database instance to point to that, I need to do a configuration change?
In my experience with Oracle, the typical unit of division is a schema. Schemas in Oracle are used more like you would use databases in SQL Server or PostgreSQL. They represent both users and a logical separation of objects. Physical separation would usually be done using tablespaces. Tablespaces are a group of physical files where data is stored. Schemas can share or use different tablespaces. Having one tablespace per schema is uncommon; they usually share a few tablespaces or often even just one.
With that in mind, to answer your questions more directly,
1) Like in any other database, you can specify the schema the object belongs to:
CREATE TABLE MY_SCHEMA.TABLE_X ( X NUMBER )
If the schemas on two CREATE statements are different, then it will create different objects. What's different in Oracle is that the default schema changes for every user. The default schema is always the currently connected schema/user. So if you omit the schema like so:
CREATE TABLE TABLE_X ( X NUMBER )
then the implied schema is the currently connected schema/user. So if I'm logged in as MY_SCHEMA, then the above is equivalent to the first example. When connecting as two different users, then the implied schema will be different and the DDL is not equivalent between the two users. So running the same statement would create two different objects if you do not specify a schema.
The two objects may be stored in the same physical file if they are in the same tablespace. (They are most likely in the USERS tablespace if you did not create one explicitly and did not specify a different default tablespace when creating the schemas.) Regardless, they are still two completely separate objects.
If you specify the schema explicitly like in the first example, then the DDL is equivalent regardless of who executes it (although permissions may prevent some users from executing it). So it would result in creating the object once, and attempting to create it a second time would result in an error unless you're using CREATE OR REPLACE or something similar.
2) I don't know the answer to this question, but as I said, in Oracle, the basic unit of separation is usually the schema, not a database. I believe the question you're asking is a large part of the reason why the schemas are used in the way they are. Having multiple actual databases on the same machine/instance is far more difficult in Oracle than in other databases (if not impossible), so it's much simpler to have a single database with many schemas.
I am reverse-engineering an application which administers an Oracle database.
Everything is new to me (application + database)
There is a statement there somewhere, which is:
SELECT * FROM XXX#YYY (XXX is a word, YYY another word)
If I go into my database with TOAD I can't find an 'XXX#YYY' table nor view. If I copy paste the statement in TOAD's editor, I get results as if the table exists.
I know that the '#' symbol is allowed for naming an Oracle object. Is it possible that it means something else here though?
How can I find the table (or view)? Is it possible to get information through a statement such as which schema does 'XXX#YYY' belong to or weather it is a table or a view, so that I can track it?
The database consists of many schemas. There is a default one. Is it possible that XXX#YYY may belong to another schema, rather than the default?
Please help me find the table.
Identifier behind # is database link. It is a way to access objects on some remote Oracle server. more info on http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_5005.htm#SQLRF01205
In Toad/Oracle XXX#YYY means object#database_link.
Look for the schema in your DB, there you will find the table.
Btw: I think its better to use SCHEMA.TABLENAME
If you have problems finding the SCHEMA, go to View->Toad Options, select Treeview at Browser style and then it should display all schemas.
I make a privileges to user on one schema at Oracle, when accessing oracle database using SSIS I saw all tables and schema. When I use SQL Plus show me only one schema.
What is the problem here?
What query are you running to see tables in SQL*Plus? If you are querying USER_TABLES, you will only see the tables that the current user owns. If you are querying ALL_TABLES, you will see all the tables that you have permission to query regardless of the owner. If you are querying DBA_TABLES, you will see all the tables in the database (though you need additional privileges to query the DBA% objects.
There is another question on how to get a list of all the tables in a database that goes into more detail about this.