Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am lefred on github.
  • I am lefred (https://keybase.io/lefred) on keybase.
  • I have a public key whose fingerprint is 3FC1 BFE9 6874 1F85 E9C1 6ACC 3330 C753 DD8A B51D

To claim this, I am signing this object:

@lefred
lefred / gist:634463dff834e1933ad6
Last active August 29, 2015 14:13
HaProxy configuration
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
uid 99
gid 99
daemon
defaults
log global
@lefred
lefred / Galera UUID
Last active November 17, 2015 07:23
From To Length Content
----- ---- ------- ---------------------------
0 31 32 Bits 0-31 of Coordinated Universal Time (UTC) as a count of 100-nanosecond
intervals since 00:00:00.00, 15 October 1582, encoded as big-endian 32-bit
number.
32 47 16 Bits 32-47 of UTC as a count of 100-nanosecond intervals since 00:00:00.00,
15 October 1582, encoded as big-endian 16-bit number.
48 59 12 Bits 48-59 of UTC as a count of 100-nanosecond intervals since 00:00:00.00,
15 October 1582, encoded as big-endian 16-bit number.
60 63 4 UUID version number: always equal to 1 (DCE UUID).
SELECT ROUND(SUM(bytes)/1024/1024*60) AS megabytes_per_hour
FROM (
SELECT SUM(VARIABLE_VALUE) * -1 AS bytes
FROM information_schema.GLOBAL_STATUS
WHERE VARIABLE_NAME IN ('wsrep_received_bytes', 'wsrep_replicated_bytes')
UNION ALL SELECT sleep(60) AS bytes
UNION ALL SELECT SUM(VARIABLE_VALUE) AS bytes
FROM information_schema.GLOBAL_STATUS
WHERE VARIABLE_NAME IN ('wsrep_received_bytes',
'wsrep_replicated_bytes')
SELECT ROUND(SUM(trx)/60) AS transactions_per_second FROM
(SELECT VARIABLE_VALUE * -1 AS trx
FROM information_schema.GLOBAL_STATUS
WHERE VARIABLE_NAME = 'wsrep_last_committed'
UNION ALL SELECT sleep(60) AS trx
UNION ALL SELECT VARIABLE_VALUE AS trx
FROM information_schema.GLOBAL_STATUS
WHERE VARIABLE_NAME = 'wsrep_last_committed') AS COUNTED;
@lefred
lefred / gist:07c9e1801ebdd5f7ff1b
Created March 1, 2016 13:28
galeraWaitUntilEmptyRecvQueue
USE test; DROP FUNCTION IF EXISTS galeraWaitUntilEmptyRecvQueue;
DELIMITER $$
CREATE
DEFINER=root@localhost FUNCTION galeraWaitUntilEmptyRecvQueue()
RETURNS INT UNSIGNED READS SQL DATA
BEGIN
DECLARE queue INT UNSIGNED;
DECLARE starttime TIMESTAMP;
DECLARE blackhole INT UNSIGNED;
SET starttime = SYSDATE();
SET GLOBAL wsrep_desync=on;
FLUSH TABLES WITH READ LOCK;
...wait until the queue rises to be quite high, about 20.000
UNLOCK TABLES; use test;
SELECT sum(trx) as transactions, sum(duration) as time,
IF(sum(duration) < 5, 'DID NOT TAKE LONG ENOUGH TO BE ACCURATE',
ROUND(SUM(trx)/SUM(duration)))
AS transactions_per_second
FROM
(SELECT VARIABLE_VALUE * -1 AS trx, null as duration
mysql2 mysql> select str_to_date('9','%m');
+-----------------------+
| str_to_date('9','%m') |
+-----------------------+
| NULL |
+-----------------------+
1 row in set, 1 warning (0.00 sec)
mysql2 mysql> show variables like 'sql_mode'\G
*************************** 1. row ***************************
@lefred
lefred / maskit.sh
Last active February 19, 2021 07:59
maskit
!#/bin/bash
# date 2017-01-23
proxy_user=admin
proxy_pwd=admin
proxy_port=6032
proxy_host=127.0.0.1
username=devel
@lefred
lefred / addition_to_sys.sql
Last active May 24, 2023 12:28
MySQL Group Replication extra functions and views to sys schema
USE sys;
DELIMITER $$
CREATE FUNCTION IFZERO(a INT, b INT)
RETURNS INT
DETERMINISTIC
RETURN IF(a = 0, b, a)$$
CREATE FUNCTION LOCATE2(needle TEXT(10000), haystack TEXT(10000), offset INT)