目录

工欲善其事

实践出真知

活跃标签: linux java mysql 待分类 js springboot win10 windows 电路 vue macOS nginx esp32 git docker idea maven esp8266 python Arduino

存档:

标签: mysql (27)

mysql 中的正则表达式

mysql 富文本内容替换 字符串方式 UPDATE child_course SET promotional_photos=replace(promotional_photos, 'child_course SET promotional_photos=REGEXP_REPLACE(promotional_photos, 'height=\".*\"', ''); 注意上面的方式是在8.0之后的!如果使用5.7的版本可以参考以下解决方法 1、开启mysql自定义函数支持 show variables like '%fun%'; log_bin_trust_function_creators=OFF表示没有开启自定义函数。输入开启命令。 set global log_bin_trust_function_creators=1; 注:此处不开启,后面自定义函数写好。调用不起作用 !执行可能需要root权限 2.编写reg....

MySql查看数据库及表容量大小并排序

查看所有数据库容量大小 select table_schema as '数据库', sum(table_rows) as '记录数', sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)', sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)' from information_schema.tables group by table_schema order by sum(data_length) desc, sum(index_length) desc; 查看所有数据库各表容量大小 select table_schema as '数据库', table_name as '表名', table_rows as '记录数', truncate(data_length/1024/1024, 2) as '数据容量(MB)', truncate(index_length/1024/1024, 2) as '索引容量(MB)' from information_schema.tab.....

mysql 记一次自以为是的翻车事件

最近在创建数据库时 打 text 发现还有个几个包含text的类型: text 65535/3=21845个汉字,约20000,存储空间占用:65535/1024=64K的数据, tinytext 最大长度255个字节(2^8-1), longtext 4294967295/3=1431655765个汉字,14亿,存储空间占用:4294967295/1024/1024/1024=4G的数据, mediumtext 16777215/3=5592405个汉字,560万,存储空间占用:16777215/1024/1024=16M的数据 想着文字不多用text(65535/3=21845个汉字)有点占用空间 就用 tinytext节省一点空间但当时不知道长度。 结果各种报错:⬇️ Caused by: java.sql.SQLException: Incorrect string value: '\xE5\x89\x8D\xE9\x9B\x86...' for column 'description' at row 1 各种搜发现好想又不是编码问题,utf8md4 也设了不管用。。还好最......

mysql 常用配置

忽略大小写配置 # 查看配置状态 SHOW VARIABLES LIKE '%case%'; # my.cnf # 设置忽略大小写 lower_case_table_names = 1; 配置group by 分组后显示多个字段 1.进入mysql 2.查询出sql_mode: SELECT @@GLOBAL.sql_mode; SELECT @@SESSION.sql_mode; SELECT @@sql_mode; 发现前面都有ONLY_FULL_GROUP_BY 3. 在命令行中输入 set @@GLOBAL.sql_mode=(select replace(@@GLOBAL.sql_mode,‘ONLY_FULL_GROUP_BY’,’’)); 以上三个sql_home都设置一遍, 退出mysql重新进入查看sql_mode;

mysql 时间函数

基本时间 now(), current_timestamp(); -- 当前日期时间 current_date(); -- 当前日期 current_time(); -- 当前时间 date('yyyy-mm-dd hh:ii:ss'); -- 获取日期部分 time('yyyy-mm-dd hh:ii:ss'); -- 获取时间部分 date_format('yyyy-mm-dd hh:ii:ss', '%d %y %a %d %m %b %j'); -- 格式化时间 unix_timestamp(); -- 获得unix时间戳 from_unixtime(); -- 从时间戳获得时间 1. 当前日期 select DATE_SUB(curdate(),INTERVAL 0 DAY) ; 2. 明天日期 select DATE_SUB(curdate(),INTERVAL -1 DAY) ; 3. 昨天日期 select adddate(now(),-1) select date_sub(now(),interval 1 day) 4. 前一个小时时间 select date_.......

Mysql 常见问题

编码问题 mysql 中的utf8编码并非真正的utf8编码如果存储表情等字符时肯定会报错,需要设置成utf8mb4编码格式 ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL mysql的设置默认是不允许创建函数 更改全局配置 SET GLOBAL log_bin_trust_function_creators = 1; 有主从复制的时候 , 从机必须要设置 不然会导致主从同步失败 更改配置文件my.cnf log-bin-trust-function-creators=1 重启服务生效

mysql 基本命令语句

mysql 数据库安装后需要配置用户,数据库和表信息: 创建用户 create user 'root'@'%' identified by '123456'; grant all privileges on . to 'root'@'%'; flush privileges; 注意第一行的 % 要和第二行的% 一致 删除用户 drop user 'user'@'127.0.0.1'; 创建数据库 create database [数据库名] default character set utf8mb4 collate utf8mb4_general_ci; 创建表 create table IF NOT EXISTS [表名] ( id int auto_increment, username varchar(255) null comment '注释', password varchar(255) null, mobile varchar(255), primary key (id) #主键 ) ENGINE = InnoDB DEFAULT CHARSET = utf8....