数据库的增删改查

1. 数据库操作

  1.查看当前用户:

  select user();

  2. 设置密码:

  set password = password('密码')

  3. 创建一个其他的用户

  create user '用户名'@ip(192.168.14.%)'identified by '123' .

    ip可以填完整的ip(192.168.14.11)或者限制网段(192.168.14.%)

  create user 'root@localhost'@'192.168.14.%'identified by '123';

  4. 给用户一个权限

  grant 权限类型 on 文件件.* to '给权限的用户名'@'ip';

     all  全部权限

     insert  添加

     select  查看

  5. 创建账号并授权

  grant all on 库名.* to '登陆的用户名'@'%' identified by '123'

  (%代表的是ip)

  6. 查看数据库

  show databases;

  7. 创建数据库

  create database 库名;

  8. 查看当前使用的数据库

  select database()

  9. 切换到当前库

2. 表操作

  1. 创建表

  create table 表名(id int,name char());

  2. 查看当前数据库所有表

  show tables;

  3. 删除表

  drop tables 表名

  4. 查看表结构

  desc 表名

  5. 新增数据

  insert into 表名 values(1,'python');

  insert into 表名(id) values ('python');

  6. 查询数据

  select * from 表名;

  7. 修改数据

  update 表名 set 字段名 = '字段内容' where id = 1;

  8. 删除数据

  delete from 表名   将表中数据清空

  delete from 表名 where id=1;  删除某一行数据

  

 

posted @ 2019-11-25 21:56  一只毛土豆儿  阅读(68)  评论(0编辑  收藏  举报