Windows终端下MySQL常用命令
1、登录命令
打开cmd后输入mysql -h+ip地址 -u+用户名 -p 之后回车会打印出Enter password:,然后输入密码回车就可以登录成功。
2、查看这个数据库连接下有哪些数据库
show databases;
3、进入其中某个数据库
use 数据库名;
4、查看数据库下都有哪些表
show tables;
5、查看表注解信息
select table_name,table_comment from information_schema.tables where table_schema='数据库名称' and table_name='表名';
tables表中提供的表信息很多,大家可以根据自己的需求去查,不过由于信息太多,展示界面不是很友好,所以这里只查了一个比较重要的注解信息。
6、查看某个表的表结构
desc 表名;
该命令只展示表的结构、表字段类型、主键信息和该属性是否可为空等属性,而不显示外键信息。
7、查看其它表中字段更多信息
select column_name,column_default,is_nullable,data_type,collation_name,column_type,column_key,column_comment from information_schema.columns where table_schema='数据库名' and table_name='表名';
information_schema.columns表中还提供了其它信息的查询,不过个人认为这个是最重要的部分信息,其它信息可根据需要进行查询。
8、复制表结构:create table 新表名称 like 模板表名称;
9、复制数据:insert into 新表名称 select * from 模板表名称;