读书人

mysql 根本操作命令

发布时间: 2013-11-08 17:52:01 作者: rapoo

mysql 基本操作命令

1. 查看端口

Netstat an

2. 登陆mysql服务器

Mysql u root p mysqlhlocahost u root p

3. 选择数据库

Show databases

4. 设置字符集

set names 'gbk';

5. 查询数据库中的表

show tables;

6. 设置字符集

set names'gbk';

7. 创建表

create tabletest(

tid int(10) not null,

tname varchar(100) notnull,

tdate datetime not null default'0000-00-00',

primary key(tid));

8. 查看表结构

desc test;

9. 增加列

alter table testadd(tage int(3));

10. 修改列的默认值

alter table test altertag set default '0';

11. 删除默认值

alter table test altertag drop default;

12. 删除列

alter table test dropcolumn tag;

13. 插入数据

insert intotest(tid,tname,tdate) value(1,'ymm','2012-11-04');

14. 删除表

drop table test;

15. 修改表名

alter tabletest rename test1;

16. 显示数据库版本

select version();

17. 刷新数据库

flush privileges;

18. 查询当前时间

select current_date;

19. 将查询出的数据写入文件

select * from test1into outfile "F:/test.txt" fields terminated by ",";

20. 查看数据库状态

status;

21. MySQL基本操作查看所有编码

show variables like'character_set_%';

22. 主键设置自子增长

tid int(10) not nullauto_increment,//设置主键的时候

alter table auto auto_increment=(10);

读书人网 >Mysql

热点推荐