MySQL基本操作经常忘记,不如记下来留用
登陆数据库
D:\phpStudy\MySQL\bin>MySQL -uroot -proot查看数据库MySQL> show da.. 
D:\phpStudy\MySQL\bin>MySQL -uroot -proot

查看数据库
MySQL> show databases;
选择数据库
MySQL> use bugfree;
设置字符集
MySQL> set names 'gbk';
查询数据库中的表
MySQL> show tables;
MySQL基本操作创建表
MySQL> create table test(
-> tid int(10) not null,
-> tname varchar(100) not null,
-> tdate datetime not null default '0000-00-00',
-> primary key (tid));
查看表结构
MySQL> desc test;
添加列
MySQL> alter table test add(tage int(3));
修改原表结构
MySQL> alter table test modify tage int(5) not null;
修改列的默认值
MySQL> alter table test alter tage set default '0';
去掉列的默认值
MySQL> alter table test alter tage drop default;
删除列
MySQL> alter table test drop column tage;
插入数据
MySQL> insert into test(tid,tname,tdate) value(1,'yangjuqi','2008-03-21');
查询数据
MySQL> select * from test;
模糊查询
MySQL> select * from test where tname like '%杨%';
修改数据
MySQL> update test set tname='张三' where tid='2';
MySQL基本操作删除数据
MySQL> delete from test where tid='2';
删除表
MySQL> drop table test;
重命名表
MySQL> alter table test rename testbak;
分页查询(limit 起始行,取多少行)
MySQL> select * from testbak limit 2,1;
刷新数据库
MySQL> flush privileges;
显示数据库版本
MySQL> select version();
显示当前时间
MySQL> select current_date;
修改用户密码
D:\phpStudy\MySQL\bin>MySQLadmin -uroot -proot password yangjuqi
将查询出的数据写入文件
MySQL> select * from testbak into outfile "d:/test.txt" fields terminated by ",";
查看数据库状态
MySQL> status;
MySQL基本操作查看所有编码
MySQL> show variables like 'character_set_%';
导入sql文件命令
MySQL>source d:/MySQL.sql;