基本的命令行操作
-- SQL注释 (--空格)
update mysq1.user set authentication_string=password('123456') where user='root' and Host =' loca1host'; -- 修改用户密码
flush privileges; -- 刷新权限
数据库xxx语言 CRUD增删改查
DDL定义
DML操作
DQL查询
DCL控制
操作数据库
-- 加个数据库
create database if not exists 库名
-- 删除一个数据库
drop database if exists 库名
-- 使用数据库
use `库名`
`` -- 如果你的表名或者字段名是一个特殊字符,就需要带` `
操作表
-- 创建数据库表
-- comment '' ''里面写注释
create table if not exists `student`(
`id` int(4) not null auto_increment comment '学号',
`name` varchar(30) not null default '匿名' comment '姓名',
`pwd` varchar(20) not null default '123456' comment '密码'
primary key(`id`)
)ENGINE=INNODB DEFAULT CHARSET=utf8
-- 删除
drop table if exists 表名
-- 修改
alter table 表名 rename as 新表名 -- 修改表名
alter table 表名 ADD age INT(11) -- 增加字段
alter table 表名 modify age varchar(11) -- 修改约束
alter table 表名 change age age1 INT(1) -- 修改字段名
alter table 表名 drop age1 -- 删除字段
show CREATE DATABASE 库名 -- 查看创建数据库的语句
show CREATE TABLE 表名 -- 查看数据表的定义语句
desc 表名 -- 显示表的结构
-- 关于数据引擎
INNODB -- 默认使用
MYISAM -- 早些年使用的
MYISAM | INNODB | |
---|---|---|
事务支持 | 不支持 | 支持 |
数据行锁定 | 不支持 | 支持 |
外键约束 | 不支持 | 支持 |
全文索引 | 支持 | 不支持 |
表空间的大小 | 较小 | 较大,约为2倍 |
常规使用操作:
- MYISAM节约空间,速度较快
- INNODB安全性高,事务的处理,多表多用户操作