MySQL相关文章索引(8)
2021-03-01 本文已影响0人
司小幽
一、工具资源
二、环境部署
64位 windows10,MYSQL8.0.13重置密码(忘记密码或者无法登录)
mysql-connector-java.jar包的下载过程详解
安装mysql老是出现“找不到VCRUNTIME140_1.dll”?这里轻松解决!!
三、基本常识
在mysql中的不等于,<>,!=,is not
select * from cinema WHERE id%2 = 1;
select * from cinema WHERE id%2 = 0;
INSERT INTO t
VALUES
(1, 20, 'a'),
(2, 26, 'b');
mysql中使用update同时更新多个字段,包括select查询
UPDATE OldData o, NewData n
SET o.name = n.name, o.address = n.address
where n.nid=234 and o.id=123;
UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def');
REPLACE(str,from_str,to_str)
limit分页公式:curPage是当前第几页;pageSize是一页多少条记录
limit (curPage-1)*pageSize,pageSize
mysql CONCAT(str1,str2,…)
round(x,d)
alter table ts01 rename to ts01_new;
DROP TABLE IF EXISTS test_table;
CREATE TABLE test_table (
ID INTEGER AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
NAME VARCHAR(20) COMMENT '姓名'
) COMMENT = '测试表';
CREATE TABLE IF NOT EXISTS `runoob_tbl`(
`runoob_id` INT UNSIGNED AUTO_INCREMENT,
`runoob_title` VARCHAR(100) NOT NULL,
`runoob_author` VARCHAR(40) NOT NULL,
`submission_date` DATE,
PRIMARY KEY ( `runoob_id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE UNIQUE INDEX indexName ON tableName(tableColumns(length))
CREATE VIEW view_students_info AS SELECT * FROM tb_students_info;
Mysql 强制使用索引 force index,提高sql查询效率
SELECT * FROM XXX_log force index(ctime) WHERE (`ctime` BETWEEN '2017-09-11 09:34:13' AND '2017-10-11 09:34:13')
and id > 27851
AND column1 = 'xxx'
AND (column2 = 'null' OR LENGTH(column2) > 91)
ORDER BY id DESC LIMIT 0, 30
alter table student add name varchar(64) not null;
alter table student modify name varchar(100) not null;
create trigger ins_stu
after insert on student for each row
begin
insert into cj ( stu_id, stu_name)
values( new.stuid, new.username);
end;
ALTER TABLE tb_emp2
ADD CONSTRAINT fk_tb_dept1
FOREIGN KEY(deptId)
REFERENCES tb_dept1(id);
使用mysql查询获取字符串的最后5个字符(Getting last 5 char of string with mysql query)
使用RIGHT(str,len)函数。返回字符串 str 中最右边的len 个字符。
”或者“用”or“表示。
四、Debug
右键以管理员身份运行
Every derived table must have its own alias(sql语句错误解决方法
mysql要求每一个派生出来的表都必须有一个自己的别名,那我给派生表加上别名即可
五、P.K.
having与where的区别:
having是在分组后对数据进行过滤
where是在分组前对数据进行过滤
having后面可以使用聚合函数
where后面不可以使用聚合
insert ignore into