1、系统管理
| mysql -h主机地址 -u用户名 -p | 连接MYSQL (在mysql/bin) |
| exit | 退出MYSQL命令 |
| mysqladmin -u用户名 -p旧密码 password 新密码 | 修改密码(在mysql/bin) |
| grant select [insert][,update][,delete]on 数据库.* to 用户名@localhost("%",表示任何主机) identified by "密码" | 增加用户 |
| mysqldump –u root –p --opt 数据库名>备份文件名 | 备份数据库(在mysql/bin) |
| mysql –u root –p < batch-file (例如备份文件名) | 使用批处理 |
| mysql.server start | 启动服务器 |
| mysql.server stop | 停止服务器 |
| msql.server --log | |
2、查询命令
| select version() | 查询版本号 |
| select current_date | 查询当前日期 |
3、显示命令
| show databases | 显示数据库列表 |
| show tables | 显示库中的数据表 |
| describe 表名 | 显示数据表的结构 |
| select * from 表名 | 显示表中的记录 |
| select what_to_select from which table [where conditions_to_satisfy and (or) where conditions_to_satisfy] | 从一个表中检索数据『满足条件』 |
| select 字段1,字段2 ,… from 表名 | 显示特定的列 |
| select * from 表名 order by 字段名 | 排序行 |
| select 字段1,包含字段2的运算式 as 新字段 from 表名 | 字段值运算操作 |
| select 字段1 is null(is not null) | 空值操作 |
| Select * from 表名 where 字段名 like(not like) “字符” 注:允许使用“_”匹配任何单个字符,而“%”匹配任意数目字符。 | 模式匹配 |
| Select * from 表名 where 字段名 regexp(not regexp)或者rlike(not rlike) l “.”匹配任何单个的字符 l 一个字符类[…]匹配方框内任何字符。例如[a],[asd],[a-z]匹配任何小写字母,[0-9]匹配任何数字。 l “*”匹配零个或者多个在它前面的东西。 l 正则表达式区分大小写[aA]。 l 如果它出现在被测试值的任何地方,模式都匹配。 l 定位,在模式开始处用“^”,结尾处用“$”,例如“^b” | 扩展正则表达式 |
| Select count(*) from 表名 Select 字段名,count(*) from 表名 group by 字段名 | 行计数 |
4、编辑命令
| use database 库名 | 使用的数据库 |
| create database 库名 | 创建数据库 |
| create table 表名 | 在数据库中创建表 |
| insert into 表名 values (“data”,”data”) | 向表中添加记录 |
| Load data infile “/path/filename” into table 表名 | 从文件中向表添加数据,文件每行包括一条记录,用定位符(tab)把值分开。 |
| drop database 库名 | 删除数据库 |
| drop table 表名 | 删除数据库中的表 |
| delete from 表名 where | 删除数据库表中的记录 |
| Update 表名 set 字段=”值” where where conditions_to_satisfy | 更新数据库表中记录的值 |
ALTER TABLE c_zd MODIFY name int NOT NULL