在菜鸟MySQL教程 进行的简单的数据库操作的学习和整理。
MySQL是一种流行的关系数据库管理系统(Relational Database Management System,RDBMS)
cmd中:
进入MySQL:
mysql -u root -p
离开:exit
mysql中语句以;结尾才能生效
SHOW DATABASES;
(似乎大小写的效果是一样的)
CREATE DATABASE study
use study;
DROP database study;
显示数据表信息:
desc book;
PS:设置id自动增加:
id INT NOT NULL AUTO_INCREMENT,
默认从1开始增加序列。指定初始值为100:
id INT NOT NULL AUTO_INCREMENT,
...
)engine=innodb auto_increment=100 charset=utf8;
DROP TABLE book;
SELECT column1,column2... FROM table
[WHERE Clause]
[LIMIT N] [OFFSET M];
UPDATE table SET field1=new, field2=new
[WHERE Clause]
DELETE from tabel [WHERE Clause]
不指定where时,删除所有数据。
delete from book where id=3;
SELECT field1,field2,... FROM table1, table2...
ORDER BY field1 [ASC / DESC], [field2...];
SELECT field1,field2,... FROM table1, table2...
WHERE condition1 [and/or condition2]...
可以用关键字BINARY设定where在比较时区分大小写:
SERLECT * from book WHERE BINARY author="RUNOOB"
SELECT field1,field2,... FROM table1, table2...
WHERE field1 LIKE condition1 [and/or field2=value]...
LIKE 类似于等号=,多与%同用,%表示任意字符,用于模糊匹配。
union连接多个select语句的结果
SELECT 语句1
UNION [ALL / DISTINCT]
SELECT 语句2;
SELECT column, function(column) FROM table
WHERE column operator value
GROUP BY column;
对于数据表employee: