美文网首页
MySQL常用命令-增删改查

MySQL常用命令-增删改查

作者: Java学习之乐 | 来源:发表于2018-08-18 20:38 被阅读0次

    MySQL常用命令

    指令作用

    指令

    查看/查询

    show,select,desc

    创建

    create

    删除

    drop,delete,truncate

    切换/进入

    use

    添加记录

    insert

    查看数据库列表

    show databases;

    查看当前数据库登入的是那个用户

    select user();

    查看当前数据库有哪些表

    show tables;

    查看test数据库的编码类型

    show create database test;

    查看test表的类型

    show create table test;

    查看test表的定义信息

    desc test;

    创建数据库

    create database db1;

    创建一个utf8mb4类型的数据库

    create database db2 DEFAULT CHARACTER SET utf8mb4;

    创建表

    CREATE TABLE students (id int UNSIGNED NOT NULL PRIMARY KEY,name VARCHAR(20)NOT NULL,age tinyint UNSIGNED);

    为emp表添加记录(有 id,name,sex,age字段)

    insert into emp (id,name,sex,age) values(1,'xiaoming','m',30);

    修改emp表的内容(第几行第几个字段)

    update emp set age=18 where id=4;

    删除数据库

    drop database db1;

    删除test表

    drop table test

    删除emp表中的记录

    delete from emp where name='lvdou';

    删除emp整个表记录

    delete from emp;

    备注:这个命令要是删除上万条记录很慢(因为他记录日志,可以利用日志还原)

    truncate table emp;这个命令删除上万条记录特别快

    因为他不记录日志

    清空emp表

    truncate table emp;

    批量执行sql程序

    mysql < hellodb_innodb.sql

    备注:也可不进入数据库的情况下查看数据库

    mysql -e 'show databases'

    相关文章

      网友评论

          本文标题:MySQL常用命令-增删改查

          本文链接:https://www.haomeiwen.com/subject/xsfqiftx.html