Primary questions mysql

1. The main task of database design and planning stage?
The necessity and feasibility of establishing a data She analysis to determine the status of systems and information, and links between the various data SHE SHE data system in the organization

2.mysql Table related rights, meaning each table?
The right information table storage account mainly: user, db, tables_priv, columns_priv , procs_priv this five tables (as well as the host table, is now integrated into the host content before the user table 5.6), its meaning are:

user table
user account information table records allows connection to the server, which is a global authority level. For example: a user in the user table DELETE permission was granted, the user can delete any record of all databases on the MySQL server.

db table
db table stores the user's authority to operate a database, the user decide which host from which database storage. User table stores a host operating rights to the database, configuration and permissions db table for a given database level privileges on the host to do more fine-grained control.

tables_priv and columns_priv table
table_priv indicates the operation permissions on the table include, select, insert, update, delete , create, drop, grant, references, index and alter.
column_priv field indicates the operating authority of the columns in the table, including select, insert, update, and references.

procs_priv tables
stored procedures and stored functions related rights

3. The index of the advantages and disadvantages?
Several basic types of indexes ordinary index unique index primary key index full-text index
index advantage
· quicker retrieval (including packet ordering)
· unique index to ensure the uniqueness of each row of data
-using the indexing procedure can be optimized concealer, improve system performance
index drawback
· insert delete modify maintenance rate of decline
that takes up physical space and data

4. characteristics of the transaction?
acid atomicity, consistency, isolation, durability

5. Create constraints purpose? The kind of constraints? How to view the constraints?
- ensure the integrity constraint object data in the table, defines the constraints of a single column of data can be entered in a table or
- OK integrity (entity integrity): a unique primary key constraint and constraint
- the integrity of the column (domain integrity): check constraint, and non-null default constraint constraint
- referential integrity: foreign key constraint
view mainly through third-party tools or sql statement:
1: Navicate for mysql, open the database, the database table view view the design table, select the foreign keys tab, you can view the foreign key
2: use the sql statement to
show create table table name; this command to see all the information tables, including some field types, constraints field, foreign keys, primary keys, index, character encoding and so on.

6.wo hang establish a standard index?

Not used frequently updated primary key column
does not allow full-text index
to create a unique index to select strong field
shorter index selection data type field, the field does not exceed a total length of 768 bytes
reasonable to create a composite index, a length value based on the actual length of the column the definition of
single-table index number no more than four
to avoid using foreign key
important SQL statements must use the index

7.varchar (50) and the meanings int (10) 50 and 10. for example.
8. Optimization select * from tb where coloumn1 in ( a, b, c) and coloumn2 = 3 and coloumn3> 5
indexed

How 9.mysql reach 100 million level table optimization?
Sub-library sub-table
> 1 vertical (longitudinal) segmentation
vertical segmentation are common Vertical Vertical library and two kinds of tables.
Vertical library according to the service coupling is, in the different databases low degree of association stored in different tables. Similar approach with large-scale systems split into multiple smaller systems, an independent division by business classification.
Vertical table is based on a database of "column" carried more of a table fields, can create an extension table

> 2 horizontal (lateral) segmentation
When an application is difficult to re-grained vertical slicing, after slicing, or a huge amount of data the number of rows, there is a single write library storage performance bottleneck, this time on the need for the horizontal segmentation.

Level segmentation into sub-table and the sub-library library sub-table, based on internal logic within the data table, the same table are distributed to a plurality of different conditions or a plurality of database tables, each table contains only part of the data, so that a small amount of data for a single table, to effect distributed.

Some typical data fragmentation rules:
1, according to the numerical ranges
according to the time interval or intervals ID segmentation. For example: by date is different months or even days of data across different libraries;
"hot and cold data separation" some systems used to migrate less, some use historical data to other libraries, the only business functions hotspot data query
2, the modulo value in accordance with
the general cut-division modulo hash mod, for example: Customer table assigned to one of four banks according cusno fields cut into the remainder is 0 in the first library, the remainder 1 is placed second library, and so on.

Sub-library sub-table can effectively link and single stand-alone libraries bring performance bottlenecks and pressure to break through the network IO, hardware resources, the number of connections the bottleneck, it also brings some problems.
1, the transaction consistency
2, cross-node correlation query join issue
3, inter-node paging, sorting, function question
4, avoid heavy primary key global issue
5, data migration, capacity expansion problem

select sum(if(score>90,score,0)) AS greatGrade, avg(if(score between 80 and 89, score,null)) AS goodGrade

Copy a table implementation, there are two structures.
Method 1: Add the create table statement like clauses end, the table structure can copy the source table to the new table, the following syntax.
create table table name like a new source table

Copy Data: insert into the new table select * from source table
method II at the end of the create table statement select statement to add a copy of the table structure can be achieved, even table records the source table may be copied into the new table. The following table syntax structure of the source table and all records of the source table is copied into the new table.
The new table create table select * from source table

create procedure productpricing()
begin
select avg(prod_price) from products;
end;

create table student(
id int primary key,
name varchar(8)
)engine=innodb default charset=utf-8 comment='xxx';

Guess you like

Origin www.cnblogs.com/ccdat/p/11266544.html