文档详情

mysql-常用命令精华版.doc

发布:2018-05-19约字共9页下载文档
文本预览下载声明
mysql 常用命令用法总结 一、启动与退出 mysqld –install 启动mysql命令 net start mysql 停止mysql命令 net stop mysql 登录命令 mysql –uroot –p(首次登录直接回车登录) 首次登录密码已存在 [mysqld] skip-grant-tables 设置密码命令 SET PASSWORD FOR root@localhost = PASSWORD(666); 查看运行各种状态值 show global status; 查询配置信息show variables; 查看慢查询 show variables like %slow%;? 查看最大连接数 show variables like max_connections; 查看缓存 show global status like qcache%; 查看数据库 show databases; 查看表 use 数据库名 - show tables; 查看表数据 select*from 表名; 查看表数据结构 show create table 表名; 或者desc 表名; 查看编码格式 show?variables?like?%char%; 设置编码格式 SET?character_set_client?=?utf8?; 退出quit或exit 二、库操作 1、创建数据库 create database 数据库名; 2、删除数据库 drop database 数据库名; 3、删除表 drop table 表名; 4、创建数据库表create table 表名 (字段名 varchar(20), 字段名 char(1)); 5、插入数据 insert into 表名 values(1,Tom,96.45); insert into 表名 values(1,Tom,96.45),(2,Joan,82.99), (2,Wang, 96.59);5、查询前几行数据 select * from 表名 order by 字段名 limit 0,2; 6、正序显示表数据 select * from 表名 order by 字段名; 7、倒叙显示表数据 select * from 表名 order by 字段名 desc; 8、删除表中数据 delete from 表名 where 字段名=值; 9、表中数据 update 表名 set name=Mary where id=1; 10、表中增加字alter table 表名 add 字段名 int(4) default 0; 11、 删除表的字段 alter table 表; 12、改表 rename table 旧表名 to 新表名; alter table 旧表名 rename 新表名; 13、修改表字段 alter table 表 change 修改前字段名? 修改后字段名称14、清空表delete from 表名; 15、更新表中数据 update 表名 set sex=f where name=test; 三、常用数据类型 类型 整数类型 tinyint 1字节 0~255 smallint 2字节 0~2的16次方-1 mediumint 3字节 0~2的24次方-1 int 4字节 0~2的32次方-1 bigint 8字节 0~2的64次方-1 浮点型非精确类型) floatfloat(7,3) 表示一共显示7位,保留小数点后面3位数 double 高精度型Decimal decimal(M,D) M:1-65 D:0-30 numeric 2.字符型 chra 表示定长字符 N取值0~255varchar 表示变长字符 N取值0~2的16次方-1 blob用来存储二进制大数据类型的,根据存储大小选择不同的类型。tinyblob、blob、mediumblob、longblob四种。 Text用来存储文本大数据类型的,同blob一样也有四种选择Binary
显示全部
相似文档