mysql -uroot -p
库相关
--查询当前mysql中所有库
--show databases
-- 创建库
-- create database 库名;
-- create database if not exists 库名;
-- 查询库的字符集
-- show create database 库名;
-- 修改库的字符集
-- alter database 库名 default character set 字符集名称;
-- 删除库
-- drop database 库名 ;
-- drop database if exists 库名 ; 如果存在这个库删除
-- 建表之前,必须使用哪个库
-- use 库名;
表相关
--建表
--字段有序(主键自增):字段名 字段类型 auto_increment primary key not null
--让字段内容不能为空:字段名 字段类型 not null;
-- create table 表名(
字段名称1 字段类型1,
字段名称2 字段类型2,
...
...
字段名称n 字段类型n
) ;
-- 查询当前库中有哪些表
-- show tables ;
-- 查看表的结构
-- desc 表名;
--删除字段
--alter table 表名 drop 字段名;
-- 修改表的字段名称
-- alter table 表名 change 旧字段名称 新的字段名称 以前的字段数据类型;
-- 修改表的字段类型 modify
-- alter table 表名 modify 字段名称 新的字段类型 ;
-- 添加一个新的字段
-- alter table 表名 add 字段名称 字段类型;
-- 复制一张表
-- create table 新表名 like 旧表名;
-- 删除表
-- drop table 表名;
-- drop table if exists 表名;
DQL语句(数据库操作语句):
--表内插入数据
--insert into 表名 values (值 1, 值 2, ...);
--insert into 表名 values (值 1, 值 2, ...),(值 1, 值 2, ...),(值 1, 值 2, ...)......;
--insert into 表名 (字段名 1, 字段名 2, ...) values (值 1, 值 2, ...);
--查看表内数据
--select * from 表名;
-*代表所有字段,实际开发中不可以用,需要写上全部字段
--删除表内指定数据
--delete from 表名 where 字段名=值;
--清空表内所有数据(仅仅只是将表的全部记录删除,表还在)
--delete from 表名;
--使用 truncate 删除表中所有记录;(删除所有数据和表,并新建一个一模一样的空表)
--truncate table 表名;
-查询mysql中所有带字符集的变量
-show variables like '%character%';
--表内带条件修改
--update 表名 set 字段名 = 值 where 条件 ;
--update 表名 set 字段名1 = 值1 , 字段名2 = 值2 ... where 条件 ;