MySQL的基本操作,表字段类型timestamp与datatime的区别

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