Skip to content

Instantly share code, notes, and snippets.

@lefred
lefred / generate_restaurants.py
Last active December 15, 2023 10:16
Restaurants JSON generator for MySQL Document Store
#!/usr/bin/python3.8
import mysqlx
import sys
from random import choice, randrange
from faker import Faker
def connect():
session = mysqlx.get_session(
@lefred
lefred / mysql_8_replication_observability.sql
Last active January 20, 2024 16:24
Get replication information
use sys;
DROP VIEW IF EXISTS replication_status_full;
CREATE
ALGORITHM = MERGE
SQL SECURITY INVOKER
VIEW replication_status_full
AS
SELECT
concat(s.channel_name, ' (', w.worker_id,')') AS channel,
c.host,
@lefred
lefred / to_optimize.sql
Last active May 18, 2023 07:03
it there should be only one query to optimize in MySQL
SELECT schema_name, format_pico_time(total_latency) tot_lat,
exec_count, format_pico_time(total_latency/exec_count) latency_per_call,
query_sample_text
FROM sys.x$statements_with_runtimes_in_95th_percentile AS t1
JOIN performance_schema.events_statements_summary_by_digest AS t2
ON t2.digest=t1.digest
WHERE schema_name NOT in ('performance_schema', 'sys')
ORDER BY (total_latency/exec_count) desc LIMIT 1\G
@lefred
lefred / func.py (json)
Last active October 14, 2022 07:54
Fn Application to store slow query log to Object Storage
import io
import json
import logging
import oci
import base64
from mysql.connector import connection
from datetime import datetime
from fdk import response
@lefred
lefred / binlog_streaming@.service
Last active June 27, 2023 09:37
binlog streaming
[Unit]
Description=Streaming MySQL binary logs to local filesystem using %i
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
ExecStart=/root/binlog_streaming/bin/binlog_to_local.sh /root/binlog_streaming/conf/%i.conf
@lefred
lefred / mysql_window.sql
Created December 23, 2021 10:28
MySQL Window Functions Example
CREATE TABLE t_win(x int AUTO_INCREMENT PRIMARY KEY);
INSERT INTO t_win
VALUES (1),
(2),
(3),
(4),
(5),
(6),
@lefred
lefred / mds_functions.sql
Last active January 12, 2023 10:55
Addition to MDS
create database mds;
SET GLOBAL log_bin_trust_function_creators = 1;
USE mds;
DROP FUNCTION IF EXISTS get_gtid_to_skip;
DELIMITER |
CREATE FUNCTION get_gtid_to_skip()
RETURNS LONGTEXT
BEGIN
@lefred
lefred / binlog_to_object_storage.sh
Last active September 10, 2021 10:02
streaming binlogs from MDS HA to Object Storage
#!/bin/bash
if [ $# -eq 0 ]
then
echo "A configuration file is required"
exit 1
fi
CONF_FILE=$1
@lefred
lefred / binlog_to_object_storage.sh
Last active September 10, 2021 09:21
streaming binlogs from MDS to Object Storage
#!/bin/bash
if [ $# -eq 0 ]
then
echo "A configuration file is required"
exit 1
fi
CONF_FILE=$1
@lefred
lefred / index.php
Last active May 28, 2021 11:54
php example
<html>
<header>
<title>PHP on OCI with MySQL Database Service</title>
</header>
<body>
<center><h1>PHP on OCI with MySQL Database Service</h1></center>
<hr>
<?php
$user = "";
$pwd = "";