[root@host]# mysql -u root -p -h 192.168.1.1
Enter password:ShaZam
mysql> exit
Bye
CREATE DATABASE 数据库名;
[root@host]# mysql -u root -p
Enter password:****** # 登录后进入终端
mysql> create DATABASE CI;
mysqladmin -u root -p create CI;
drop database <数据库名>;
mysql> drop database CI
mysqladmin -u root -p drop CI;
[root@host]# mysql -u root -p
Enter password:******
mysql> use CI;
Database changed
mysql>
To be continue
CREATE TABLE table_name (column_name column_type);
CREATE TABLE IF NOT EXISTS `ci_diff`(
`id` INT UNSIGNED AUTO_INCREMENT,
`title` VARCHAR(100) NOT NULL,
`author` VARCHAR(40) NOT NULL,
`submission_date` DATE,
PRIMARY KEY ( `id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE table_name ;
root@host# mysql -u root -p
Enter password:*******
mysql> use CI;
Database changed
mysql> DROP TABLE ci_diff
Query OK, 0 rows affected (0.8 sec)
mysql>
INSERT INTO table_name ( field1, field2,...fieldN ) VALUES ( value1, value2,...valueN ),(),();
SELECT column_name,column_name FROM table_name [WHERE Clause] [LIMIT N] [ OFFSET M]
你可以使用 LIMIT 属性来设定返回的记录数
你可以通过OFFSET指定SELECT语句开始查询的数据偏移量。默认情况下偏移量为0。
SELECT field1, field2,...fieldN FROM table_name1, table_name2... [WHERE condition1 [AND [OR]]
condition2.....
UPDATE table_name SET field1=new-value1, field2=new-value2 [WHERE Clause]
DELETE FROM table_name [WHERE Clause]
SELECT field1, field2,...fieldN FROM table_name WHERE field1 LIKE condition1 [AND [OR]] filed2 = somevalue'
LIKE 通常与 % 一同使用,类似于一个元字符的搜索。
SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions]
UNION [ALL | DISTINCT]
SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions];
DISTINCT: 可选,删除结果集中重复的数据。默认情况下 UNION 操作符已经删除了重复数据,所以 DISTINCT 修饰符对结果没啥影响。
ALL: 可选,返回所有结果集,包含重复数据。
SELECT field1, field2,...fieldN table_name1, table_name2...ORDER BY field1, [field2...] [ASC [DESC]]
SELECT column_name, function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;
SELECT coalesce(name, '总数'), SUM(singin) as singin_count FROM employee_tbl GROUP BY name WITH ROLLUP;
- 连接的使用: 多张表的数据汇总成一种形式的数据
- INNER JOIN(内连接,或等值连接):获取两个表中字段匹配关系的记录。
- LEFT JOIN(左连接):获取左表所有记录,即使右表没有对应匹配的记录。
- RIGHT JOIN(右连接): 与 LEFT JOIN 相反,用于获取右表所有记录,即使左表没有对应匹配的记录。
INNER JOIN 代表关联表
ON 代表之间相同的字段
WHERE 代表从数据库获取对应的数值
SELECT a.diff_id, a.revision_id, b.board_name, b.process_type, COUNT(*) as numm, a.username FROM phab_monitor a INNER JOIN phab_compile_result b ON a.diff_id = b.diff_id where a.diff_id=391517 group by b.board_name;
IS NULL: 当列的值是 NULL,此运算符返回 true。
IS NOT NULL: 当列的值不为 NULL, 运算符返回 true。
<=>: 比较操作符(不同于=运算符),当比较的的两个值为 NULL 时返回 true。