来自 stackoverflow 的内容居多。

1- MySQL VARCHAR size?

2- 数据库设计范式

3- What is InnoDB and MyISAM in MySQL ?

4- 为什么手写DDL?

5- Data access object (DAO) in Java

MySQL VARCHAR size?

Q:

I'm wondering, if I have a VARCHAR of 200 characters and that I put a string of 100 characters, will it use 200 bytes or it will just use the actual size of the string?

A:

100 characters.

This is the var (variable) in varchar: you only store what you enter (and an extra 2 bytes to store length upto 65535)

If it was char(200) then you'd always store 200 characters, padded with 100 spaces

See the docs: "The CHAR and VARCHAR Types"  ------- by gbn

补充:

VARCHAR(M)是一种比CHAR更加灵活的数据类型,同样用于表示字符数据,但是VARCHAR可以保存可变长度的字符串。其中M代表该数据类型所允许保存的字符串的最大长度,只要长度小于该最大值的字符串都可以被保存在该数据类型中。因此,对于那些难以估计确切长度的数据对象来说,使用VARCHAR数据类型更加明智。MySQL4.1以前,VARCHAR数据类型所支持的最大长度255,5.0以上版本支持65535字节长度,utf8编码下最多支持21843个字符(不为空)  ------ 来自百度百科

数据库设计范式

如何能设计出优秀的数据库呢?专家们经过多年研究终于·····  一般按照范式来进行数据库设计就得到良好的数据库,范式的目的在于:消除数据冗余和编程便利。

第一范式就是得到纯二维表, // 只有纯二维的表才能装进数据库

第二范式是消除非主键依赖关系, // “有些列并不直接依赖于主键”,就是说和主键没关系的东西应该扔到另外一张表中去。

第三范式是消除函数依赖关系。// 能算出来的就别额外拿一列装了。。。

做范式的主要手段是“拆表”,但是要它有副作用,······,所以要在数据冗余和编码容易之间寻找平衡点,到了第三范式,基本上就是平衡点了。  ------ 《 Java 就该这样学》

What is InnoDB and MyISAM in MySQL ?

InnoDB and MYISAM, are storage engines for MySQL.

These two differ on their locking implementation: InnoDB locks the particular row in the table, and MyISAM locks the entire MySQL table.

You can specify the type by giving MYISAM OR InnoDB while creating a table in DB.    ------ by Siva

为什么手写 DDL (Data Definition Language)?

schema.sql(demo:

-- 数据库初始化脚本

-- 创建数据库
CREATE DATABASE chat;
-- 使用数据库
use chat; -- 创建表
CREATE TABLE user(
user_id BIGINT NOT NULL AUTO_INCREMENT COMMENT '用户id',
username VARCHAR(40) NOT NULL COMMENT '用户名(邮箱)',
password VARCHAR(40) NOT NULL COMMENT '密码',
nickname VARCHAR(20) NOT NULL COMMENT '昵称',
other VARCHAR(120) COMMENT '其他',
PRIMARY KEY (user_id)
)ENGINE=InnoDB AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8 COMMENT='用户基本信息'; CREATE TABLE friend_relation(
user_id BIGINT NOT NULL COMMENT '用户id',
friend_id BIGINT NOT NULL COMMENT '好友id'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='好友关系表'; CREATE TABLE group_relation(
user_id BIGINT NOT NULL COMMENT '用户id',,
group_id BIGINT NOT NULL COMMENT '群组id'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='群组关系表'; -- 初始化数据
INSERT INTO
'user'('username', 'password', 'nickname', 'other')
VALUES
('11122@gmail.com', 123456, '老大', '这人很懒,啥也没写'),
('jhgm49@163.com', 123456, '老二', '平平淡淡才是真'); -- INSERT INTO
-- 'friend_relation'('user_id', 'friend_id')
-- VALUES -- 为什么手写 DDL ( Data Definition Language )
-- 记录每次上线的 DDL 修改
-- 上线 V 1.1
-- xxx
-- 上线 V 1.2
-- xxx x x

MySQL 如果表存在就删掉:

DROP TABLE IF EXISTS tbl_name;

Data access object (DAO) in Java

Q:

I was going through a document and I came across a term called DAO. I found out that it is a Data Access Object. Can someone please explain me what this actually is?

I know that it is some kind of an interface for accessing data from different types of sources, in the middle of this little research of mine I bumped into a concept called data source or data source object, and things got messed up in my mind.

I really want to know what a DAO is programmatically in terms of where it is used. How it is used? Any links to pages that explain this concept from the very basic stuff is also appreciated.  ------ by Vasanth Nag K V

A:

The Data Access Object is basically an object or an interface that provides access to an underlying database or any other persistence storage.

That definition from: http://en.wikipedia.org/wiki/Data_access_object

Check also the sequence diagram here: http://www.oracle.com/technetwork/java/dataaccessobject-138824.html

Maybe a simple example can help you understand the concept:

Let's say we have an entity to represent an employee:

public class Employee {

    private int id;
private String name; public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} }

The employee entities will be persisted into a corresponding Employee table in a database. A simple DAO interface to handle the database operation required to manipulate an employee entity will be like:

interface EmployeeDAO {

    List<Employee> findAll();
List<Employee> findById();
List<Employee> findByName();
boolean insertEmployee(Employee employee);
boolean updateEmployee(Employee employee);
boolean deleteEmployee(Employee employee); }

Next we have to provide a concrete implementation for that interface to deal with SQL server, and another to deal with flat files, etc.  ------ by Rami

小白的 MySQL 笔记(一)的更多相关文章

  1. MySQL笔记汇总

    [目录] MySQL笔记汇总 一.mysql简介 数据简介 结构化查询语言 二.mysql命令行操作 三.数据库(表)更改 表相关 字段相关 索引相关 表引擎操作 四.数据库类型 数字型 字符串型 日 ...

  2. 涂抹mysql笔记-数据库中的权限体系

    涂抹mysql笔记-数据库中的权限体系<>能不能连接,主机名是否匹配.登陆使用的用户名和密码是否正确.mysql验证用户需要检查3项值:用户名.密码和主机来源(user.password. ...

  3. centos7.2下安装Mysql笔记

    centos7.2下安装Mysql笔记 安装 MySQL 适用于 CentOS 7.0 或以后版本: yum install mariadb mariadb-server 适用于 CentOS 6.8 ...

  4. MySQL笔记(六)游标练习

    23.3.1 Trigger Syntax and Examples 意义不明的几道练习,留着备用. 感觉不好写,而且难以调试..不知道以后会不会有实际的应用场景. 环境:MySQL 笔记(三)由 t ...

  5. mysql 笔记(一)

    mysql 笔记 预留 mysql> use mysql; mysql> grant all privileges  on *.* to root@'%' identified by &q ...

  6. 【MySQL笔记】SQL语言四大类语言

     SQL语言共分为四大类:数据查询语言DQL,数据操纵语言DML,数据定义语言DDL,数据控制语言DCL.   1. 数据查询语言DQL 数据查询语言DQL基本结构是由SELECT子句,FROM子句, ...

  7. Mysql 笔记二

    Mysql 笔记二 Mysql 笔记二 Table of Contents 1. 前言 2. Master Thread 工作方式 2.1. 主循环(loop) 2.2. 后台循(backgroup ...

  8. 深入浅出mysql笔记---1、mysql下载安装

    深入浅出mysql笔记---1.mysql下载安装 一.总结 一句话总结: linux下rpm安装即可 1.linux的wget命令作用? 下载文件的工具:比如wget http://cn.wordp ...

  9. 深入浅出mysql笔记---0、序

    深入浅出mysql笔记---0.序 一.总结 一句话总结: 心得:买书之前建议先找找电子书,纸质书太难带了 1.开源作用? 开源对mysql的发展至关重要 2.mysql在2002年就全面支持了事务, ...

随机推荐

  1. Codeforces543BDestory Roads心得

    题目描述: In some country there are exactly n cities and m bidirectional roads connecting the cities. Ci ...

  2. 微信公众号批量爬取java版

    最近需要爬取微信公众号的文章信息.在网上找了找发现微信公众号爬取的难点在于公众号文章链接在pc端是打不开的,要用微信的自带浏览器(拿到微信客户端补充的参数,才可以在其它平台打开),这就给爬虫程序造成很 ...

  3. 腾讯 AI Lab 计算机视觉中心人脸 & OCR团队近期成果介绍(3)

    欢迎大家前往腾讯云社区,获取更多腾讯海量技术实践干货哦~ 作者:周景超 在上一期中介绍了我们团队部分已公开的国际领先的研究成果,近期我们有些新的成果和大家进一步分享. 1 人脸进展 人脸是最重要的视觉 ...

  4. 利用阿里云Centos7建站过程

    以下可能不尽详述,如有问题欢迎指出 准备过程:1. 阿里云主机一台2.域名一个 3.github个人帐号开始: 1.以root帐号登录云主机 2.安装apache [root@192 ~]# yum ...

  5. SSD: Single Shot MultiBoxDetector英文论文翻译

    SSD英文论文翻译 SSD: Single Shot MultiBoxDetector 2017.12.08    摘要:我们提出了一种使用单个深层神经网络检测图像中对象的方法.我们的方法,名为SSD ...

  6. Uncaught TypeError: download is not a function at HTMLAnchorElement.onclick (index.html:25)

    前段时间调试html报了这样的一个错误 Uncaught TypeError: download is not a function     at HTMLAnchorElement.onclick ...

  7. codeup模拟赛 进击的二叉查找数

    问题 B: 进击的二叉查找树 时间限制: 1 Sec 内存限制: 64 MB 提交: 1017 解决: 379 提交状态 题目描述 给定1~N的两个排列,使用这两个排列分别构建两棵二叉查找树(也就是通 ...

  8. memcache 启动 储存原理 集群

    一. windows下安装启动 首先将memcache的bin目录加入到Path环境变量中,方便后面使用命令: 然后执行 memcached –dinstall 命令安装memcache的服务: 然后 ...

  9. 76、django之内置Admin

    本篇导航: 配置路由 定制Admin Django内置的Admin是对于model中对应的数据表进行增删改查提供的组件,使用方式有: 依赖APP: django.contrib.auth django ...

  10. centos7 忘记mysql root密码办法

    1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的状态下,其他的用户也可以任意地登录和 ...