您的位置:首页 > 数据库 > SQL

MySQL operation

2016-04-13 20:18 746 查看

Loading Data into a Table

(1)Loading data from a file like this:

mysql> LOAD DATA LOCAL INFILES '/path/pet.txt' INTO TABLE pet


->LINES TERMINATED BY '\r\n';


**if generate a load error,like the command is not useful,

when entry mysql,add this “local_infile=1”

for instance:

mysql -u root - p –local-infile=1 -e “LOAD DATA LOCAL INFILE “/path/text” INTO TABLE XXX FILEDS TERMINATED BY ‘,’**

(2)directly insert:

mysql> INSERT INTO pet


-> VALUES('paffbal','diane','1990-03-30',NULL);


Retrieving information from a table

The general form of the statement is:

SELECT what_to_select


FROM which_table


WHERE conditions_to_satisfy


ORDER BY which_column;


the default sort order is ascending,if what to in reverse order add DESC keyword to the name of the column you sorting by.

you can sort on multiple columns,and you can sort different columns in different directions.

When you do an ORDER BY ,NULL values are presented first.

Pattern matching

SQL pattern matching enables you to use “_” to match any single character and “%” to match an arbitrary number of characters.In MySQL, SQL patterns are case-insensitive by default.You do not use = or <> when you use SQL patterns, use the LIKE or NOT LIKE comparison operation instead.

to find names beginning with “b”:

mysql> SELECT * FROM pet WHERE name LIKE 'b%';


to find names ending with “fy”:

mysql> SELECT *FROM pet WHERE name LIKE '%fy';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: