MySQL 备份数据库 mysqldump -uroot -p(数据库登入密码)(要备份的数据库名称)> (文件名接. sql)mc.sql
还原数据库, 首先创建一个数据库 create database mc; 进入库 use mc;
还原数据库 source /root/mc.sql
修改数据表
添加字段:
alter table 表名 add 字段名 列类型 [not null|null](not null 不能为空)mull 能为空 [primary key] 主建 [unique] 不能重复 [auto_increment] 自动增长[default value](默认值)
alter table 表名 add 字段定义 after ar_id;
删除字段:
alter table 表名 drop 字段名
修改字段:
alter table 表名 modify 字段名 字段新类型
完整修改字段:
alter table 表名 change 旧字段名称 新字段定义
修改表名称
alter table 表名 rename 新名字
删除表
drop table [if (not) exists] 表名;
表中行的操作
insert
insert [into] 数据表名称 [(字段列表)] values|value (表达式 | null|default,...),(表达式 | null|default,...)
insert [into] 数据表名称 set 字段名称 = 值,...
insert 与 insert...set 的区别是后者可以带有子查询.
update -- 单表
update 表名 set 字段名称 = 值,... [where 条件]
如果省略 WHERE 条件将更新全部记录.
删除记录 -- 单表
delete from 数据表名称 [where 条件]
如果省略 where 条件, 将删除全部记录
常用 SELECT 命令
使用 select 命令查看 MySQL 数据库系统信息:
-- 打印当前的日期和时间
select now();
-- 打印当前的日期
select curdate();
-- 打印当前的时间
select curtime();
-- 打印当前数据库
select database();
-- 打印 MySQL 版本
select version();
-- 打印当前用户
select user();
-- 查看系统信息
- show variables;
- show global variables;
- show global variables like '%version%';
show variables like '%storage_engine%'; 默认的存储引擎
like 模糊搜索还可用户 where 字句, 例如
查询 students 表中年龄为 20 岁的学生
- MySQL> use HA;
- MySQL> select * from students where age like '2%';
查看系统运行状态 show processlist 查看 MySQL 连接数 一个
来源: http://www.bubuko.com/infodetail-3073199.html