MySql学习笔记

select version(), current_date;
select user(), current_date;


shell>mysql --help


mysql >SELECT
- >USER()
- >\c
mysql > 
//取消当前MySql语句


mysql >SELECT * FROM my_table WHERE name = 'Smith AND age < 30;
    '> '\c
mysql >
//等待完成字符(‘)或者字符串(“)


mysql >DESCRIBE pet;
//查看表的结构


mysql >LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet
- >LINES TERMINATED BY '\r\n';
// Windows


mysql >LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet
- >LINES TERMINATED BY '\r'
// MacOS


mysql >INSERT INTO pet
- >VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
// 数据插入


select what_to_select
from which_table
where conditions_to_satisfy;


mysql >UPDATE pet SET birth = '1989-08-31' WHERE name = 'Bowser';


mysql >SELECT * FROM pet WHERE species = 'dog' AND sex = 'f';


mysql >SELECT * FROM pet WHERE species = 'snake' OR species = 'bird';


mysql >SELECT * FROM pet WHERE (species = 'cat' AND sex = 'm')
- >OR (species = 'dog' AND sex = 'f');


mysql >SELECT name, birth FROM pet;


mysql >SELECT DISTINCT owner FROM pet;
//去重复查询


mysql >SELECT name, species, birth FROM pet
- >ORDER BY species, birth DESC;
//默认升排序,字符串使用order by binary col_name


mysql >SELECT name, birth, CURDATE(),
- >TIMESTAMPDIFF(YEAR,birth,CURDATE()) AS age
- >FROM pet;
//| name | birth | CURDATE() | age |
//| Fluffy | 1993-02-04 | 2003-08-19 | 10 |
//时间差计算


mysql >SELECT name, birth, death,
- >TIMESTAMPDIFF(YEAR,birth,death) AS age
- >FROM pet WHERE death IS NOT NULL ORDER BY age;


mysql >SELECT name, birth, MONTH(birth) FROM pet;
//查询下个月生日


mysql >SELECT name, birth FROM pet WHERE MONTH(birth) = 5;
//查询指定月份生日


mysql >SELECT name, birth FROM pet
- >WHERE MONTH(birth) = MOD(MONTH(CURDATE()), 12) + 1;
//查询下个月有生日的宠物


 “_”匹配任何单个字符 “%”匹配任意数量的字符(包括零字符)

你可能感兴趣的:(Game)