mysql> SHOW DATABASES;
mysql> CREATE DATABASE MYSQLDATA;
mysql> USE MYSQLDATA; (按回车键出现Database changed 时说明操作成功!)
mysql> SHOW TABLES;
mysql> CREATE TABLE MYTABLE (name VARCHAR(20), sex CHAR(1));
mysql> DESCRIBE MYTABLE;
mysql> insert into MYTABLE values (”hyq”,”M”);
mysql> LOAD DATA LOCAL INFILE “D:/mysql.txt” INTO TABLE MYTABLE;
mysql>use database;
mysql>source d:/mysql.sql;
mysql>drop TABLE MYTABLE;
mysql>delete from MYTABLE;
mysql>update MYTABLE set sex=”f” where name=’hyq’;
13.查询时间:select now();
查询当前用户:select user();
查询数据库版本:select version();
查询当前使用的数据库:select database();
14、删除student_course数据库中的students数据表:
rm -f student_course/students.*
15、备份数据库:(将数据库test备份)
mysqldump -u root -p test>c:\test.txt
备份表格:(备份test数据库下的mytable表格)
mysqldump -u root -p test mytable>c:\test.txt
将备份数据导入到数据库:(导回test数据库)
mysql -u root -p test<c:\test.txt
16、创建临时表:(建立临时表zengchao)
create temporary table zengchao(name varchar(10));
17、创建表是先判断表是否存在
create table if not exists students(……);
18、从已经有的表中复制表的结构
create table table2 select * from table1 where 1<>1;
19、复制表
create table table2 select * from table1;
20、对表重新命名
alter table table1 rename as table2;
21、修改列的类型
alter table table1 modify id int unsigned;//修改列id的类型为int unsigned
alter table table1 change id sid int unsigned;//修改列id的名字为sid,而且把属性修改为int unsigned
22、创建索引
alter table table1 add index ind_id (id);
create index ind_id on table1 (id);
create unique index ind_id on table1 (id);//建立唯一性索引
23、删除索引
drop index idx_id on table1;
alter table table1 drop index ind_id;
24、联合字符或者多个列(将列id与":"和列name和"="连接)
select concat(id,':',name,'=') from students;
25、limit(选出10到20条)<第一个记录集的编号是0>
select * from students order by id limit 9,10;
26、MySQL不支持的功能
事务,视图,外键和引用完整性,存储过程和触发器