1, the command syntax:
nsert into <table name> [(<field name 1>) [, ..... <field name>])] values (value 1) [, (n-value)]
2, create a simple test table test
mysql> use oldboy Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables ; +------------------+ | Tables_in_oldboy | +------------------+ | student | +------------------+ 1 row in set (0.00 sec) mysql> create table test( -> id int(4) not null auto_increment, -> name char(20) not null, -> primary key(id) -> ); Query OK, 0 rows affected (0.07 sec) mysql> show tables; +------------------+ | Tables_in_oldboy | +------------------+ | student | | test | +------------------+ 2 rows in set (0.00 sec)
3. Insert data into the table
1 , is inserted into the first test data table MySQL > INSERT INTO test (ID, name) values (1, ' Oldboy ' ); Query the OK, 1 Row affected (0.05 sec) MySQL > SELECT * from test; + - - + -------- + | the above mentioned id | name | + ---- + -------- + | 1 | Oldboy | + ---- + ------- - + . 1 row in SET (0.00 sec) 2 , since as the id of the self-energizing, therefore, can only be inserted in the column name value MySQL > iNSERT INTO Test (name) values ( ' oldgirl ' ); Query the OK, . 1 row affected (0.00 sec) MySQL > the SELECT *from the Test; + ---- + --------- + | the above mentioned id | name | + ---- + --------- + | 1 | Oldboy | | 2 | oldgirl | + --------- + ---- + 2 rows in SET (0.00 sec) . 3 , if the column is not specified, it is necessary for the value of each column outlaw properly inserted MySQL > SELECT * from Test; + ----------- + ---- + | the above mentioned id | name | + ---- + ----------- + | 1 | Oldboy | | 2 | oldgirl | | 3 | zhangxuan | + ---- + ----------- + 4 rows in the SET (0.00 sec) 4 , bulk insert data method, suggesting that efficiency MySQL > iNSERT INTO the Test (the above mentioned id, name ) values (. 4, ' engchao'),(5,'geili'); Query OK, 2 rows affected (0.05 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> select * from test; +----+-----------+ | id | name | +----+-----------+ | 1 | oldboy | | 2 | oldgirl | | 3 | zhangxuan | | 4 | engchao | | 5 | geili | +----+-----------+ 5 rows in set (0.00 sec)