mysql数据库的基本操作

mysql数据库的基本操作
dos命令
启动mysql服务:net start mysql
启动数据库: mysql -uroot -p
查看所有的数据库:show databases;
新建数据库:create databas 数据库名;
删除数据库:drop databas 数据库名;
打开数据库:use 数据库名;
查看所有的表:show tables;
新建数据表:create table 表名(字段名 类型,.....);
添加数据:insert into 表名 {可选字段} values(数据....);
删除表:drop table 表名;
复制表:create table 新表 select * from 旧表;
select * into 旧表 from 新表;
只复制表结构:create table 新表 select* from 旧表 where 1=0;
修改表结构:
添加一个字段
alter table 表名 add 字段名 类型;
修改某个字段
alter table 表名 cheage 字段名 新字段名 类型;
删除字段
alter table 表名 drop column 字段名;
创建索引:create index 索引名字 on 表名 (字段) 将某字段作为索引
删除索引:drop index 表名.索引名;