例子:select
SUBSTRING_INDEX(thumbnail,'/',-1) as file_name,
thumbnail,
SUBSTRING_INDEX(thumbnail,'.',-1) as suffix,
from tb_article where thumbnail != '';
介绍:这里用到 MySQL 的 SUBSTRING_INDEX(str,delim,count) 函数,LENGTH(str) 函数,REPLACE(str,from_str,to_str) 函数,和数据库的一张辅助表help_topic(这张表在默认的mysql库里)。SUBST
MySQL 使用用 insert 插入数据时,为了不重复插入,往往先查询一下数据,若不存在才进行插入操作。当数据库中存量数据较多时,或者是在批量插入操作时,很容易出现插入重复数据的问题。解决方法:在 MySQL 中,当存在主键冲突或唯一键冲突的情况下,根据插入策略不同,有以下三种避免方法:insert ignore into:若没有则插入,若存在则忽略replace into:若没有则正常插入,若存在则先删除后插入insert into ... on duplicate key update:若没有则正常插入,若存在则更新注意,使用以上方法,需要表中有一个 PRIMARY KEY 或 UNIQ
使用 MySQL 线程池对压力测试的影响,下面使用两个文件,分别测试一下。代码:test1.js 使用了 MySQL 线程池:export async function test1(ctx) {
let pool = dbUtil.getPool();
let connection = await pool.getConnection();
let [rows] = await connection.query('select * from tb_user limit 10');
connection.release();
}
test2.js 未使用 MySQL 线程池:export
DATE_FORMAT(date, format)DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据。format 参数的格式有:%a Everyday name in Shortened form [Sun–Sat].
%b Month name in Shortened form [Jan – Dec].
%c Name of Month in numbers [0 – 12].
%D Daytime of the month in a numeric form, trailed by suffix [like 1st, 2nd, …].
%d Daytime of the