注意:单词的首字母无须大写连接服务器 1. window dos 命令 mysql -h localhost -u root -p 回车输入密码( -h可以不写默认为本地服务器) Mysql 命令数据库的操作 1. show databases //显示数据库 2. use databasename(use 后直接加数据库名字); // 使用数据库 3. create database databasename //创建数据库 4. Drop database databasename //删除数据库 5. show tables; //显示表 6. Drop table tablename; //删除一张表 7. Create table class( stu int, Name varchar(20), Age int, Are varchar(20) ); create table score( id int primary key auto_increment, name varchar(20), Ke varchar(20), Fen int )charset utf8; // 创建表( 自动增长的不用插入值) table oldtablename to newtablename; // 修改表名 (iption) tablename //显示表的结构(描述表) 10./c //在语句出错时退出 12. 默认情况下字符集编码 utf-8 , window 下为 gbk 因此需要声明: set names gbk; //gbk 可以换成其他的字符集编码例如 utf8; 13. insert into tablename(id,name)values(1,'song'); //插入单行 into tablename (id,name) values (1,'song'),(2,'song2'),(3,'song3');// 插入多行 15. Update tablename set id=2,name='wang' where id=1; 16. Delete from tablename where id=2; 详解数值类型整型 Tinyint 默认范围是有符号的 Tinyint (M) unsigned zerofill default Unsigned 无符号类型(非负)影响存储范围 M 代表宽度(在 zerofill 才有意义) Zerofill 代表零填充(默认为无符号) Not null Default 默认值浮点型/ 定点型 Float(D,M) Decimal(D,M) 更精确些 D: 总的位数(不包括小数点) M :小数的位数 4或8 个字节 Float(4,2) 范围--- Float(4,2) 如果用 unsigned 修饰范围为 -- 字符型定长和变长区别: ;变长大 Char 当不够 M个字符时用空格补齐取出时把空格删除,如果数据本身有空格将丢失而定长不会丢失空格 Text 较大时使用两万到六万字,没有默认值,搜索较慢时间日期型 Year 范围 1901--2155 Date 范围 1000-01-01--9999-12-30 典型格式 1989-10-25 Time 典型格式 hh:mm:ss 时间戳(使用 int ) 范围 1970-01-01 00000 到现在的毫秒数 Sql 语句 Where: in Select * from tablename where in(4,5)// 查询在值在4,5时模糊查询 Like % 任意字符'_' 单个字符 Select * from tablename where name like 'song%'; slelect count(*)from person; // 查询有多少行 Group by 将分组然后使用聚合函数 Select shop_id ,max(shop_price) from goods group by shop_id;// 按 shop_id 分组查出每组中 shop_price 最大的 Select shop_id ,count(*) from goods group by shop_id;// 按 shop_id 分组查出每组有多少个; 将列明当作变量来使用可以做相应的加减乘除运算 Select shop_price1-shop_price2 from goods; Having 对结果进行筛选 Select shop_price1-shop_price2 as sheng from good
mysql应用(精) 来自淘豆网m.daumloan.com转载请标明出处.