Chapter X database
10.1 Introduction Database
1, database concepts database server: essentially a computer, the computer is installed on the server database management software, database management system RDBMS: essentially a C / S structure Socket software library (folder) | table (files) recorded: extract all the features of a typical object / data
2, the database management system / software Category: Relationship Type: There table structure, before accessing the data must first define the table structure, data must be stored in accordance with the type of the field or constraints typical: MySQL, Oracle, DB2, SQL server non-relational : access data are based on the key: value in the form of non-relational: Mongodb, redis, memcache
10.2 mysql installation and service production system
1, installation, and environment variables
2, the mysqld made software system services Note: First turn off the mysqld before making
C: \ Windows \ system32 > tasklist | findstr mysqld mysqld.exe 8372 Console 2 454 , 916 K C: \ Windows \ system32 > taskkill / F / PID 8372 Success: PID has been terminated for the 8372 process.
Production :( Run as Administrator cmd)
mysqld - install View: Windows + r enter services.msc
3, start:
No production system services Start: 1 , start the server mysqld 2 , start the client MySQL - -uroot - the p- - H127. 0.0 . 1 - P 3306 If you are logged mysqld server in the machine can be abbreviated: MySQL - -uroot - the p- complete production system services after a mouse click can enable or disable MySQL: Windows + r type services.msc find mysql, startup or shutdown
4, crack the administrator password
1 , turn off the mysqld server 2 to bypass the way the grant tables start mysqld server from the command line mysqld - Skip-Grant-the Tables 3 , the client directly to the non-root user password to log in, change the password MySQL - -uroot - P MySQL > Update . MySQL User SET password = password ( " 123 ") WHERE User = "the root" and Host = "localhost"; the #Query the OK, 0 rows affected ( 0.00 sec) #rows Matched: . 1 the Changed: 0 Warnings: 0 mysql > flush privileges ; the #Query the OK, 0 rows affected ( 0.00 sec) 4 , at the command line using taskkill to kill mysqld service, and then start a normal mysqld taskkill / F / PID 131 312 5 , logon with the new password mysql - -uroot - P123
5, Unicode
1 , a new directory in the mysql installation My. INI file
2 , modify My. INI
[ Mysqld ] Character - SET - Server = UTF8 collation - Server = utf8_general_ci [ Client ] default - Character - SET = UTF8 [ MySQL ] User = "the root" password = '' default - Character - SET = UTF8 . 3 , restart mysqld 4 , restart the client login, enter \ s View results
Create user and authorization:
the Create the User ' Egon ' @ ' . 192.168.13% ' IDENTIFIED by ' 123 ' ; # create user MySQL - uegon - P123 - . h192 168.13 . 254 # connect to the database Grant All # all permissions Grant the SELECT ON db1. * to ' egon ' @ ' 192.168.13%. ' ; # granting permissions to check all the tables under the user name egon db1 Grant the SELECT ON db1. * to ' Egon ' @ ' 192.168.13%. ' IDENTIFIED by ' 123 ' ; the SELECT the User (); # # View the current user name in the same time creating a user granted permission to check all the tables under db1
10.3 The basic sql statement
10.31 folder (library)
# By the Create Database db1 (charset utf8); # change the ALTER Database db1 GBK charset; # check to see all the library name library show databases; separate viewing information on a library Show the Create Database db1; # delete drop Database db1;
10.32 file (table)
First switch folders: use db1; the SELECT Database (); # to view the current folder where the # increasing the Create the Table T1 (the above mentioned id int , name char ); # change the ALTER the Table T1 the Modify name char ( 16 ); # check to see the current library all the table names show tables; view details t1 table Show the Create the table t1; see table structure desc t1; # delete drop the table t1;
The contents of the file line 10.33 (record)
#增 insert (into) db1.t1 values (1,'egon'), (2,'alex'), (3,'lxx'); #改 update db1.t1 set name='sb' where id > 1; #查 select id,name from (db1.)t1; #删 delete from db1.t1 wherename = "SB"; #delete table is used to remove some of the matching records Delete from T1; ID # does not reset the increment to 0 TRUNCATE T1; # empty table, reset the entire table, id also reset
10.34 table type of storage engine
Method 1: When building table designation (different storage engines corresponding to a different storage mechanism)
Create Table T1 (ID int ) Engine = InnoDB; # t1.frm (table structure) t1.ibd (data) stored in the hard disk Create Table T2 (ID int ) Engine = MyISAM; # t2.frm (table structure) t2.MYD (data) t2.MYI (index) is stored in the hard disk Create table T3 (ID int ) Engine = blackhole; # black hole t3.frm (table structure) does not exist the data table Create table T4 (ID int ) Engine = memory; # T4 .frm (table structure) is stored in the server memory off empty (Show Create table T1;) INSERT ( INTO ) db1.t1 value ( . 1 ); INSERT( INTO ) db1.t2 value ( . 1 ); INSERT ( INTO ) db1.t3 value ( . 1 ); INSERT ( INTO ) db1.t4 value ( . 1 ); SELECT * from db1.t1; ID # . 1 SELECT * from DB1. T2; ID # . 1 SELECT * from db1.t3; # empty SELECT * from db1.t4; ID # . 1 server data off empty (empty)
Method 2: Specify the default storage engine in the configuration file
[mysqld] default-storage-engine=INNODB innodb_file_per_table=1