mysql数据库常用基本sql语句(库、表)

show global variables like ‘port’;

查看mysql使用的端口是多少

库:

  1. show databases;

显现所有数据库

  1. create database [if not exists] 数据库名;

创建数据库

  1. drop database [if exists] 数据库名;

删除数据库

  1. show create database 数据库名;

显示创建数据库语句

  1. select database();

查看当前是连接哪个数据库

  1. use 数据库名;

使用数据库

表:

  1. show tables;

查询当前数据库中的全部表

  1. show create table 表名;

显示创建表的语句

  1. describe/desc 表名;

查看表结构

  1. drop table [if not exists] 表名;

删除表

  1. alter table 原表名 rename to 新表名;

修改表名

  1. alter table 表名 add 字段名 字段类型;

添加字段

  1. alter table 表名 change 原始字段名 新的字段名 新数据类型 [默认值] [注释];

修改字段名、字段数据类型、【默认值】、【注释】

例:alter table table01 change id id01 int default 10 comment ‘序号’;

–将table01表中的字段id改名为id01,数据类型为int,默认值为10,注释为“序号”

  1. alter table 表名 modeify [column] 字段名 字段类型 [默认值] [注释];

修改字段的数据类型、【默认值】、【注释】

  1. alter table 表名 drop [column] 字段名

删除字段

扩展:

注释:

  1. select table_name 表名,table_comment 表注释,table_schema

from information_schema.tables

where table_schema = ‘数据库名’

order by table_name;

查看数据库中的所有表注释

  1. select table_name 表名,table_comment 表注释,table_rows 数据量

from information_schema.tables

where table_schema = ‘数据库名’

order by table_name;

查看数据库下的所有表的表名、表注释及其数据量

  1. select column_name 字段名,column_comment 字段注释

from information_schema.columns

where table_name=’表名’ and table_schema=’数据库名’;

查看数据库下的表的表字段注释

  1. select a.table_name 表名,a.table_comment 表注释,b.column_name

表字段,b.column_type 字段类型,b.column_comment 字段注释

from information_schema.tables a,information_schema.columns b

where b.table_name=a.table_name and a.table_schema=’数据库名’;

查看数据库下的所有表的表名、表注释以及对应表字段注释

  1. alter table 表名 comment ‘注释内容’;

修改表注释

  1. alter table 表名 modify column 字段名 字段类型 comment ‘注释内容’;

修改表的表字段注释

注意:字段名和字段类型照写就行,如果之前有规定长度 这里也要指定一下

© 版权声明
THE END
喜欢就支持一下吧
点赞114赞赏 分享
评论 抢沙发
头像
欢迎光临不念博客,留下您的想法和建议,祝您有愉快的一天~
提交
头像

昵称

取消
昵称代码图片

    暂无评论内容