Database : in accordance with the data structure to organize, based on computer storage devices warehouse storage and management of data. Word is storing data warehouse
Classification database : network databases, hierarchical databases, relational database structure.
If the database according to the storage medium to the point: the relational database (stored on disk), the sub-type non-relational database (stored in memory)
Relational model consists of:
1, the relational data structures : refers to in what way the data is stored, is stored in the form of a twodimensional table
2, the relationship between the set of operations : how to store and manage data associated with the corresponding. SQL command
3, the relationship integrity constraints : the internal data corresponding to the relationship, and also the corresponding relationship between the data and the data
Tables in the relationship: the corresponding specific columns corresponding to data stored in smart (not prosecuted)
Constraints between tables: natural entity is a corresponding relationship (foreign key)
A typical relational database:
Small type relational databases: Microsoft Access, SQLite
The type of relational databases: SQL Sever, Mysql
Large type relational databases: Oracle, DB2
SQL Category:
1, Data Query Language (DQL: data query language)
Dedicated to query data: representing instructions to select, show
2, the data operation statement (DML: data Manipulation language)
Dedicated to write data: the representative of command: INSERT, Update, the Delete
3, transaction processing language (TPL)
Designed for the safe handling of the transaction: Transaction
4, data control language statement (DCL)
Devoted to rights management: representing instructions to grant, revoke
5, data definitions language (DDL)
Dedicated configuration management: representing instructions create, drop (alter)
Start and stop Mysql Service:
Command line:
net start mysql start the service
net stop mysql service shut down
Mysql login and logout system:
log in:
1 , find mysql.exe (via cmd console: If you specify during the installation mysql.exe path where the environment variable, you can directly access; if not, then it must enter into mysql.exe path where)
2, corresponding to the input address server: -H: -H Host [the IP address / domain name]
3. Enter the server Mysql listening port: -P: port -P: 3306
4, enter the user name: -u: -u username: root
5, enter the password: -p : password -p: root
Connection authentication basic syntax:
Mysql.exe / mysql -h host address -P port -u user name -p password
Precautions
1, usually the default port can be: MySQL strong port is usually 3306
2, enter a password can enter -p, direct exchange line, then the cipher text password
drop out:
Disconnect the server: usually Mysql a limited number of server, client once used up, it is recommended they should be disconnected.
Recommend ways: using SQL instructions provided
Exit; // exit with a semicolon
\ q; // quit abbreviation
Quit:
Several commonly used keywords in the database
Row : Line
Column:列(field)
The basic operation of the database
1. Create a database
The basic syntax : create database database name [library options];
Library options: Related property database
Character Set: charset character set, representing all the current data table stored in the database default character set specified (if the current is not specified, then the use of DBMS default)
Proof set: COLLATE collation set
Create database database name of the charset character set names ;
2, display database
All basic syntax: show databases;
Display some basic syntax show databases like 'pattern match';
_ : Match the current position of a single character
% : More characters that match the specified location
3, display database creation statement
The basic syntax show create database database name;
4. Select the database
The basic syntax for use database name;
5, modify the database
Modify the database character set (database options): character sets and proof sets
The basic syntax alter database database name of the charset = character set;
6, delete the database
The basic syntax: drop Database database name;
Delete although simple, but remember to make safety: Make sure there is no problem data. (important)
After you delete the database: storing data corresponding folder will be deleted ( opt files are also deleted)
The basic operation of the data table
1, create a data table (to have a database)
Create a common table
The basic syntax: the Create the Table table name ( field name field type [ Field Properties ], field name field type [ Field Properties ], ...) [ Table Option ]
Assignment existing table structure
The basic syntax: the Create the Table new table like table name ; // Just use the database . Table name, you can access other database table name in any database
A (Table existing copy only replicated structure: if the data table has not copied)
2, the display data table
All the tables show tables;
Match display table show tables like 'pattern match';
Display table structure essential meaning: a display field information (name, type, properties, etc.) contained in the table
Describe 表名
Desc table
show columns from 表名
The Create Table statement to view data statements at the time of table creation: This statement has not seen the results of previously entered by the user.
show create table 表名;
Mysql in a variety of statement terminator
; And \ G effect is represented by the same, is the field in the row sideways, with the following corresponding data
\ G word segments vertically on the left side, the right side of the data sideways
3, setting the table properties
Table attribute refers to the table option: Engine , charset and collate
The basic syntax: ALTER Table Table Option Lists [=] value ;
4, modified table structure
Modify the table name rename table the old table to the new table name;
Modify table options alter table table table option [=] new value
New field alter table table add [column] new field name Column type [column properties] [position first / after field name ]
Fields Location: Location field you want to store the
First: before a certain (first), the first field
After field names: Place in a specific field after (the default)
Changes to field names : ALTER Table table name change the old field name new field name field type [column genus properties ] [new position]
Modify the field type (attribute ): ALTER Table table modify field names new type [new attributes] [new position]
Delete field : the ALTER the Table table name drop field names
Delete table structure
Basic grammar: drop the Table table name [, list name 2 ...] , you can delete multiple tables at the same time
Operating data base
1, insert the essential meaning: The data in SQL stored in the designated data table (field) inside the form
The basic syntax: specified field data is inserted into the table
Insert into table [(field list)] values (corresponding to the field list)
2 , query operation
Lookup table all the data: the SELECT * from table name ; // * to match all fields
Some of the fields in the query table: the SELECT list of fields from table name; // list of fields use a comma "," separated
Simple conditional query data: SELECT field list / * from table where field = value; // mysql == no sign
3, delete
The basic syntax: the Delete from table [where conditions ]; // if there is no where conditions: means that the system will automatically delete all the data in the table (with caution)
4, the update operation update: The data can be modified (usually modify some field data)
The basic syntax: Update table set field name = new value [where conditions ]; // if there is no where condition, all the tables in the corresponding field will be modified to a uniform value.
Character Set :
Mysql.exe if informed Mysqld.exe corresponding character set type to GBK ? set names gbk;
Shortcuts: the SET names the character set