代码改变世界

mysql笔记

2014-03-04 23:01  每天努力一点点  阅读(103)  评论(0编辑  收藏  举报

1. 登陆mysql数据库

mysql -uroot -p

然后再输入密码

2. 显示所有数据库

show databases;

3. 创建数据库

create database testdb;

4. 选择指定数据库

use testdb;

5. 显示当前数据库中所有表

show tables;

6. 创建表

create table student (id int primary key,name varchar(100) );

7. 插入数据

insert into student values(1,'jerry');

insert into student(id,name) values(2,'tom');

8. 查询表数据

select * from student;

select * from student where id=1;

9. 删除表数据

delete from student where id=1;

10. 更新表数据

update student set name='jerry1' where id=1;

11. 删除表

drop table student;

 

12. MySQL中的数据类型(摘自:http://www.cnblogs.com/mr-wid/archive/2013/05/09/3068229.html

MySQL有三大类数据类型, 分别为数字、日期\时间、字符串, 这三大类中又更细致的划分了许多子类型:

· 数字类型

· 整数: tinyint、smallint、mediumint、int、bigint

· 浮点数: float、double、real、decimal

· 日期和时间: date、time、datetime、timestamp、year

· 字符串类型

· 字符串: char、varchar

· 文本: tinytext、text、mediumtext、longtext

· 二进制(可用来存储图片、音乐等): tinyblob、blob、mediumblob、longblob