MySQL的基本操作,表字段类型timestamp与datatime的区别
实操MySQL DDL、DML、DCL1. DDL
2. DCL
//登陆
mysql -u root -p //root为数据名
//查询数据库
show databases;(必须分号结束)
//查询表
show tables;
3. DML
//创建用户
create user 'xxw'@localhost indentified by '123456'
//给用户授权
grant create,alter,drop,select on xxw.* to xxw@localhost;
//查看权限
show grants for xxw@localhost;
//撤销权限
revoke create on xxw.* from xxw@localhost;
//删除用户
drop user xxw@localhost;
//修改密码
alter user xxw@localhost identified by '123456';
字段类型timestamp与datatime的区别
//增
INSERT `user` SET `name`='admin',`pwd`=`5445saswuq`;
//删
DELETE FROM `user` WHERE `id`=5
//查
SELECT `id`,`name` FROM `user`
//改
UPDATE `user` SET `name`='zhu' WHERE `id`=5;
timestamp存储需要4个字节,它的取值范围为“1970-01-01 00:00:01” UTC ~ “2038-01-19 03:14:07” (和时区有关).
timestamp取值显示的时候时间是根据时区来显示的.
认识PDO
datetime存储需要8个字节,取值范围为“1000-01-01 00:00:00” ~ “9999-12-31 23:59:59”(和时区无关)
【文章原创作者:高防ip http://www.558idc.com/gfip.html欢迎留下您的宝贵建议】
//用pdo基类链接数据库
$dsn = 'mysql:host=localhost;dbname=xxw';
try {
$db = new PDO($dsn, 'xxw', '123456');
} catch (PDOException $e) {
die('连接失败' . $e->getMessage());
}