命令行工具使用数据库

来源:互联网 发布:烟台市网络党校电脑管 编辑:程序博客网 时间:2024/06/04 00:50
1.连接数据:-u指用户名 -p指密码mysql -uroot -p输入密码2.查看数据库中的文件show databases3.连接数据库文件use 文件名4.查看数据库中的所有表show tables5.新建表(primary key主键;not null非空;auto_increment自动增长)create table 表名(字段1 类型 主键 primary key not null auto_increment,字段2 类型,.......)创建表方法1create table 表名(字段1 字段1类型 primary key,字段2 字段2类型,........)方法2create table 表名(字段1 字段1类型 primary key not null auto_increment,字段2 字段2类型,........)primary key设置该字段为逐渐,在一张表中只能有一个主键,主键数据必须唯一auto_increment 自动增长6.对表中数据进行增删改操作添加insert into 表名(字段1,字段2....)values(值1,值2.....)修改:update 表名 字段1=值1,字段2=值2删除delete from 表名 where 条件查询selet * from 表名 where 条件7.对数据库中的数据结构进行增删改查操作
DESC 表名:查看表结构修改表名称:alter table 原表名 rename 新表名 修改字段类型:alter table 表名 modify 字段名 字段类型删除表:drop table 表名修改字段名称:alter table 表名 change 原字段名 新字段名 新字段类型添加字段:alter table 表名 add 新字段名 字段类型 约束条件删除字段: alter table 表名 drop 字段名      (慎用)将某个字段放在表中的第一个位置:alter table 表名 modify 字段1 字段类型 first将某个字段放在表中的指定位置的后面:alter table 表名 modify 字段1 字段类型 after 字段2
 
原创粉丝点击