mysql基本语法

登录

mysql -u root -p password

  • 显示数据库 show databases;
  • 判断是否存在数据库test,有的话先删除 drop database if exists test;
  • 创建数据库 create database test1;
  • 删除数据库 drop database test1;
  • 使用该数据库 use test1;

  • 显示数据库中的表 show tables;
  • 先判断表是否存在,存在先删除 drop table if exists student;
  • 创建表
    create table student(
    id int auto_increment primary key,
    name varchar(50),
    sex varchar(20),
    date varchar(50),
    content varchar(100)
    )default charset=utf8;
  • 删除表 drop table student;
  • 查看表的结构 describe student;

数据

  • 插入数据 insert into student values(null,'aa','男','1988-10-2','......');
  • 查询表中的数据 select id,name from student;
  • 修改某一条数据 update student set sex='男' where id=4;
  • 删除数据 delete from student where id=5;

你可能感兴趣的:(mysql基本语法)