CrystalRays的技术博客

博客已迁移至 https://icystal.top

MySQL学习小记(一)——入门内容的整理

use 数据库;--选择要使用的数据库

select 字段 from 数据表  ;-- 显示对应数据表的对应字段

select * from 数据表  ;-- 显示对应数据表的所有字段

alter table 数据表 add primary key(ID);-- 添加主键

insert into 数据表 values(字段1的值, 字段2的值, ... );-- 向数据表中插入记录

alter table 数据表1 drop foreign key fk_数据表1_数据表2;-- 删除外键

alter table 数据表 drop column 字段  ;-- 删除字段

alter table 数据表 add 字段 int unsigned not Null;-- 新建无符号整数非空字段

update 数据表 set 字段1=值1 where 字段2=值2;-- 修改字段2值为值2的记录的字段1的值为值1

alter table 数据表 modify column 字段 类型 ;-- 修改字段类型

delete from 数据表 where id>=2 ;-- 删除≥2的记录

update 数据表 set id=3 where id=7 ;-- 修改id=7的记录的id值为3

select aes_decrypt(aes_encrypt('中文', 'aa'), 'aa'),  aes_encrypt('中文', 'aa');--加解密示例

CREATE UNIQUE INDEX 引索 ON 数据表 (字段)--创建唯一引索

SHOW  (global/session) VARIABLES LIKE 'auto_inc%';--显示变量及它的值


rename table 数据表1 to 数据表2;--将数据表1重命名为数据表2

hex(aes_encrypt('hati','123'));--转换到16进制

UNHEX(参数);--从16进制换回来

select b into @afrom c where id=2  ;-- 将数据表c中id=2的记录的字段b的值返回到变量a中

select convert(now(),char);--获取当前时间并转换到字符串

CAST(数据 AS 类型); --另一个类型转换函数

declare a int default 0; --申明一个局部变量a的类型为整数,默认值为0

set 变量名(:)=值; --为变量赋值,冒号可有可无

@a 用户变量 @@a 会话变量 不用declare


评论

© CrystalRays的技术博客 | Powered by LOFTER