mysql

MySQL学习【SQL语句上】

守給你的承諾、 提交于 2021-02-19 10:48:31
1.连接服务端命令 1.mysql -uroot -p123 -h127.0.0.1 2.mysql -uroot -p123 -S /tmp/mysql.sock 3.mysql -uroot -p123 -hlocalhost 4.mysql -uroot -p123 2.mysql登陆后的一些命令 1.\h或者help   查看帮助 2.\G       格式化查看数据(以key:value形式) 3.\T 或 tee    记录日志 4.\c       结束命令 5.\s或者status  查看状态信息 6.\. 或者source  导入sql数据 7.\u 或use    使用数据库 8.\q或exit或quit  退出 3.mysqladmin的一些使用 1.查看mysql存活状态 [root@db01 ~]# mysqladmin -uroot -p123 ping 2.查看mysql状态信息 [root@db01 ~]# mysqladmin -uroot -p123 status 3.关闭mysql进程 [root@db01 ~]# mysqladmin -uroot -p123 shutdown 4.查看mysql参数 [root@db01 ~]# mysqladmin -uroot -p123 variables 5.删除数据库 [root@db01 ~]#

面试官问:你说说Redis的几个过期策略?

这一生的挚爱 提交于 2021-02-19 10:47:41
在使用redis时,一般会设置一个过期时间,当然也有不设置过期时间的,也就是永久不过期。当设置了过期时间,redis是如何判断是否过期,以及根据什么策略来进行删除的。 设置过期时间 expire key time(以秒为单位) 这是最常用的方式 setex(String key, int seconds, String value) 字符串独有的方式 除了字符串自己独有设置过期时间的方法外,其他方法都需要依靠expire方法来设置时间如果没有设置时间,那缓存就是永不过期如果设置了过期时间,之后又想让缓存永不过期,使用persist key 三种过期策略 定时删除 在设置key的过期时间的同时,为该key创建一个定时器,让定时器在key的过期时间来临时,对key进行删除 优点: 保证内存被尽快释放 缺点: 若过期key很多,删除这些key会占用很多的CPU时间,在CPU时间紧张的情况下,CPU不能把所有的时间用来做要紧的事儿,还需要去花时间删除这些key 定时器的创建耗时,若为每一个设置过期时间的key创建一个定时器(将会有大量的定时器产生),性能影响严重 懒汉式式删除 key过期的时候不删除,每次通过key获取值的时候去检查是否过期,若过期,则删除,返回null。 优点: 删除操作只发生在通过key取值的时候发生,而且只删除当前key,所以对CPU时间的占用是比较少的

Debian安装MariaDB

心不动则不痛 提交于 2021-02-19 10:47:07
环境: Debian9 安装 sudo apt update sudo apt install mariadb-server 验证安装是否成功 systemctl status mariadb 配置 进入mysql CLI: use mysql; 建立用户和密码,并授权远程访问: grant all privileges on *.* to root@'%' identified by 'password'; 刷新权限,使之生效 flush privileges; 查看用户信息 select user,host,port from user; 来源: oschina 链接: https://my.oschina.net/u/4416864/blog/3624966

Percona 5.6 Docker Image cannot load my /etc/mysql/conf.d/*.cnf

六眼飞鱼酱① 提交于 2021-02-19 09:15:50
问题 I am struggling on this issue for at least 14 hours so far :(. I am configuring a build server with docker, jenkins, java, scala on top of CentOS 7. While working with liquibase and jooq:codegen, I need to have proper MySQL(Percona:5.6) containers setup, but unfortunately, it seems that Official Percona Image (Percona:5.6) does not load *.cnf files under /etc/mysql/conf.d properly, which I do think it is my issue, such as file permissions issues. I was following with the instructions from:

MySQL 8 Calculating Average by Partitioning By Date

隐身守侯 提交于 2021-02-19 09:12:23
问题 I've setup a fiddle here: https://www.db-fiddle.com/f/snDGExYZgoYASvWkDGHKDC/2 But also: Schema: CREATE TABLE `scores` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `shift_id` int unsigned NOT NULL, `employee_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `score` double(8,2) unsigned NOT NULL, `created_at` timestamp NOT NULL, PRIMARY KEY (`id`) ); INSERT INTO scores(shift_id, employee_name, score, created_at) VALUES (1, "John", 6.72, "2020-04-01 00:00:00"), (1, "Bob", 15.71, "2020

MySQL 8 Calculating Average by Partitioning By Date

醉酒当歌 提交于 2021-02-19 09:09:50
问题 I've setup a fiddle here: https://www.db-fiddle.com/f/snDGExYZgoYASvWkDGHKDC/2 But also: Schema: CREATE TABLE `scores` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `shift_id` int unsigned NOT NULL, `employee_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `score` double(8,2) unsigned NOT NULL, `created_at` timestamp NOT NULL, PRIMARY KEY (`id`) ); INSERT INTO scores(shift_id, employee_name, score, created_at) VALUES (1, "John", 6.72, "2020-04-01 00:00:00"), (1, "Bob", 15.71, "2020

MySQL 8 Calculating Average by Partitioning By Date

本秂侑毒 提交于 2021-02-19 09:05:39
问题 I've setup a fiddle here: https://www.db-fiddle.com/f/snDGExYZgoYASvWkDGHKDC/2 But also: Schema: CREATE TABLE `scores` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `shift_id` int unsigned NOT NULL, `employee_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `score` double(8,2) unsigned NOT NULL, `created_at` timestamp NOT NULL, PRIMARY KEY (`id`) ); INSERT INTO scores(shift_id, employee_name, score, created_at) VALUES (1, "John", 6.72, "2020-04-01 00:00:00"), (1, "Bob", 15.71, "2020

How to show relational data in yii2

我们两清 提交于 2021-02-19 08:59:21
问题 I'm having trouble understanding how relations work in yii 2 I have 2 tables in a mysql database, author and book. book has a column named author which links to the id of the author table via foreign key. I've generated CRUD using gii, and I want the author name to appear in the list view, as well as dropdowns for the author name in the create and update views. But I cant seem to get the relation working even in the list view. Here's my code Book Model: <?php namespace app\models; use Yii;

MySQL dense rank for each group/partition

岁酱吖の 提交于 2021-02-19 08:57:39
问题 I am trying to build a dense rank kind of functionality but not exactly dense rank. I want to rank each group but within each group I want to keep the rank same for same values. I've written the following query which gives me a dense rank kind of functionality SELECT id, item_code @curRank := @curRank + 1 AS rank FROM table t, (SELECT @curRank := 0) r WHERE <several filters> Whereas, I want this The closest question I found is this one MySQL give a rank to each group Please help. 回答1: You can

MYSQL: SELECT sum of field values while also SELECTing unique values?

百般思念 提交于 2021-02-19 08:43:19
问题 I'd like to count the number of purchases of each item while also, depending on who's viewing the content, show whether the user has purchased the content. Because the number of items and purchases could become large I'm reluctant to throw in more JOINs to accomplish this because that would seem not performant. Basically, I'd like to have a did_i_buy field somewhere in the following query without adding another JOIN . Is this possible? Let's say for user_name=tom : SELECT Items.item_id, item