1. Knowledge of the database
DB database: a container for storing data
DBMS database management system: software for managing databases
Database application system: all systems that use a database
database:
Relational database: Oracle, DB2, SQL SERVER, MYSQL
Non-relational database: ORDBMS: object-oriented database technology, NoSQL: structured database technology.
SQL: Structured Query Language (Structured Query Language) contains 6 parts
Database Query Language (DQL) -> data query
Database Operation Language (DML) -> Addition, deletion and modification
Transaction Processing Language (TPL)
Data Control Language (DCL)
Data Definition Language (DDL) -> Build a database, build a table, build constraints
Pointer Control Language (CCL)
2. MySQL basics
1. Start the database:
①. Open through the service list: Right-click on the taskbar of the computer-Task Manager [shortcut key ctrl+shift+esc]-Click on the service list-query mysql related service names by name
②. Open by command: Enter the net start database name and net stop database name in the DOS window
2. Connect to the database (similar to java environment variables need to be configured)
①Under DOS window
Full name: mysql -uroot -p1234656 -hlocalhost -P3306
-u: user user-the user who connects to the database
-p: password-the password to connect to the database
-h: host-the ip address to connect to the database
-P: Port port number-the port number of the database
②Visualization tool (Navicat)
2. Commonly used commands of the database
shoe databases;------>Show all databases
use database name; ------>use database
show tables; ------> show all tables in the library
create database database name; ------>Create database
drop database database name; ------>Delete database
3. There are two types of database storage engines:
InnoDB: supports transactions and foreign keys, the operation efficiency is relatively low
MyISAM: does not support transactions and foreign keys, the operation efficiency is higher
4. Common types
JAVA | Java notes | MYSQL | MYSQL notes |
---|---|---|---|
Int | Short integer | int | Short integer |
long | Long integer | bigint | Long integer |
float | Single precision | float | Single precision |
double | Double precision | double | Double precision |
bigdecimal[class] | Financial data | decimal | Financial data |
String | String | char | Immutable string |
varchar | Variable string | ||
Boolean | Boolean value | Bit | Values 0 and 1 |
5. Common grammar
/*基本查询语句*/
SELECT 表的列名1,表的列名2,....FROM 数据源;
/*去重*/
语法: SELECT DISTINCT 列名,..
/*设置别名*/
用法:列 as 别名
/*比较运算*/
语法
SELECT <selectList>
FROM table_name
WHERE 条件1 AND/OR 条件2;
/*范围查找*/
BETWEEN AND[是闭区间]
/*几个关键字*/
集合查询- IN
空值查询 IS NULL
/*模糊查询*/
LIKE
通配符:%代表多个字符;_代表一个字符
/*结果排序*/
ORDER BY 出现在SELECT语句的最后
语法:
SELECT <selectList> FROM table_name WHERE 条件 ORDER BY 列名1 [ASC/DESC],列名2 [ASC/DESC]...;
升序:ASC 默认不写
降序:DESC
/*分页*/
语法:
SELECT * FROM table_name LIMIT ?,?;
SELECT * FROM table_name LIMIT beginIndex,pageSize;
beginIndex = (currentPage-1) * pageSize;
第一个?: 表示本页,开始索引(从0开始).
第二个?: 每页显示的条数
/*聚集函数*/
COUNT:统计结果记录数 如果列的值为null 不会计算在内的
MAX: 统计计算最大值
MIN: 统计计算最小值
SUM: 统计计算求和
AVG: 统计计算平均值 如果列的值为null 不会计算在内的
/*分组函数*/
语法格式:
SELECT 聚集函数或者分组的列 FROM table_name WHERE 条件 GROUP BY 列名 HAVING 分组之后的条件;