目录
1. MySQL 笔记
1.1. mwb 是什么文件
MWB 文件 MWB 是 MySQL Workbench 的默认文件格式, 包含所有数据库的结构和数据。MWB 格式可以直接导入到 MySQL 中, 使得数据库的迁移变得更加简单。在 MySQL Workbench 中, 创建 MWB 文件可以通过选择"File"菜单下的"New Model"选项。也可以使用快捷键 (Ctrl+Shift+N) 创建一个新的 MWB 文件。
1.2. mysql 函数
1.2.1. mysql 中 to_char() 和 str_to_date() 函数
- mysql 内置函数, 在 mysql 里面利用 str_to_date()把字符串转换为日期。
示例: 分隔符一致, 年月日要一致
select str_to_date('2016-09-09 15:43:28','%Y-%m-%d %H:%i:%s');
select str_to_date('2016-09-09 08:43:28', '%Y-%m-%d %h:%i:%s');
注: H 大写和 h 小写的区别? H 大写是指的是: 24 小时制; h 小写是指的是 12 小时制;
- mysql 日期和字符相互转换方法
date_format(date,'%Y-%m-%d') -------------->oracle 中的 to_char();
str_to_date(date,'%Y-%m-%d') -------------->oracle 中的 to_date();
%Y: 代表 4 位的年份
%y: 代表 2 为的年份
%m: 代表月, 格式为 (01……12)
%c: 代表月, 格式为 (1……12)
%d: 代表月份中的天数, 格式为 (00……31)
%e: 代表月份中的天数, 格式为 (0……31)
%H: 代表小时, 格式为 (00……23)
%k: 代表 小时, 格式为 (0……23)
%h: 代表小时, 格式为 (01……12)
%I: 代表小时, 格式为 (01……12)
%l : 代表小时, 格式为 (1……12)
%i: 代表分钟, 格式为 (00……59)
%r: 代表 时间, 格式为 12 小时 (hh:mm:ss [AP]M)
%T: 代表 时间, 格式为 24 小时 (hh:mm:ss)
%S: 代表 秒, 格式为 (00……59)
%s: 代表 秒, 格式为 (00……59)
SELECT DATE_FORMAT(20160909154540,'%Y-%m-%d %H:%i:%s')
DATE_FORMAT(20160909154540,'%Y-%m-%d %H:%i:%s')
1.3. Sample database
1.3.1. Sakila Sample Database
https://dev.mysql.com/doc/sakila/en/sakila-installation.html
mysql -u root -p
mysql> SOURCE C:/temp/sakila-db/sakila-schema.sql;
mysql> SOURCE C:/temp/sakila-db/sakila-data.sql;
mysql> USE sakila;
Database changed
mysql> SHOW FULL TABLES;
+----------------------------+------------+
| Tables_in_sakila | Table_type |
+----------------------------+------------+
| actor | BASE TABLE |
| actor_info | VIEW |
| address | BASE TABLE |
| category | BASE TABLE |
| city | BASE TABLE |
| country | BASE TABLE |
| customer | BASE TABLE |
| customer_list | VIEW |
| film | BASE TABLE |
| film_actor | BASE TABLE |
| film_category | BASE TABLE |
| film_list | VIEW |
| film_text | BASE TABLE |
| inventory | BASE TABLE |
| language | BASE TABLE |
| nicer_but_slower_film_list | VIEW |
| payment | BASE TABLE |
| rental | BASE TABLE |
| sales_by_film_category | VIEW |
| sales_by_store | VIEW |
| staff | BASE TABLE |
| staff_list | VIEW |
| store | BASE TABLE |
+----------------------------+------------+
23 rows in set (0.01 sec)
mysql> SELECT COUNT(*) FROM film;
+----------+
| COUNT(*) |
+----------+
| 1000 |
+----------+
1 row in set (0.00 sec)