Putty: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
apt install git
git clone https://github.com/datacharmer/test_db
cd test_db
mysql < employees.sql
Dynamic variables:
- Mysql: https://dev.mysql.com/doc/refman/5.7/en/dynamic-system-variables.html
- Mariadb: https://mariadb.com/kb/en/library/server-system-variables/
- How to calculate innodb log file size: https://www.percona.com/blog/2008/11/21/how-to-calculate-a-good-innodb-log-file-size/
- ERRATA: innodb_strict_mode - set to 1 to change warnings to errors (to ensure MySQL will stop you from inserting bad data to database).
- Mysql: https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html
- MariaDB: https://mariadb.com/kb/en/mariadb/sql-mode/
-
https://dev.mysql.com/doc/refman/5.7/en/innodb-deadlocks-handling.html
-
TASK inspiration: https://www.xaprb.com/blog/2006/08/08/how-to-deliberately-cause-a-deadlock-in-mysql/
- FK on myISAM
CREATE TABLE parent (
id INT NOT NULL,
name varchar(128),
PRIMARY KEY (id)
) ENGINE=MyISAM;
CREATE TABLE child (
id INT,
parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id)
REFERENCES parent(id)
ON DELETE CASCADE
) ENGINE=MyISAM;
SHOW CREATE TABLE child;
- SQL MODES
SELECT @@GLOBAL.sql_mode;
INSERT INTO parent VALUES('123test', 'Foo Bar');
SELECT * FROM parent;
SET SESSION sql_mode='';
INSERT INTO parent VALUES('123test');
SHOW WARNINGS;
SELECT * FROM parent;
- Row level permissions HOWTO: https://mariadb.com/resources/blog/protect-your-data-row-level-security-mariadb-100
- Howto install percona toolkit: https://www.percona.com/doc/percona-toolkit/3.0/installation.html
-
Percona slow log rate limiting: https://www.percona.com/doc/percona-server/LATEST/diagnostics/slow_extended.html
-
general log
SHOW VARIABLES LIKE "%general%";
SET GLOBAL general_log=ON;
- slow log
SHOW VARIABLES LIKE "%slow%";
SET GLOBAL slow_query_log=ON;
SHOW VARIABLES LIKE "%time%";
SET GLOBAL long_query_time=0.1;
UPDATE salaries SET salary=salary*2;
UPDATE salaries SET salary=salary+2;
pt-query-digest /var/lib/mysql/localhost-slow.log
- binary log
log_bin=localhost-binary
systemctl restart mysql
# do updates/inserts
mysqlbinlog /var/lib/mysql/localhost-binary.000001
vim /root/.my.cnf
[client]
password=YOURSECRETPASSWORD
chmod 600 /root/.my.cnf
- Secure non password auth. Only root user can log to root account.
- Poland SPZ: https://hackaday.com/2014/04/04/sql-injection-fools-speed-traps-and-clears-your-record/
- SQL injection trivia:
SELECT * FROM table WHERE id=$variable;
$variable="15; UPDATE TABLE users;"
https://app.com/show.php?variable=15; UPDATE TABLE
db: SELECT * FROM table WHERE id=15; UPDATE TABLE users;
$sql =prepare SELECT * FROM table WHERE id=?
query $sql, $variable
db: SELECT * FROM table WHERE id="15; UPDATE TABLE users"
- SSL performance issue: https://www.percona.com/blog/2013/10/10/mysql-ssl-performance-overhead/
- ProxySQL + SQL: https://www.percona.com/blog/2017/09/19/proxysql-improves-mysql-ssl-connections/
- Connection rate plugin: https://mysqlserverteam.com/the-connection_control-plugin-keeping-brute-force-attack-in-check/
- Percona XtraBackup: https://www.percona.com/software/mysql-database/percona-xtrabackup
TASK: xtrabackup: https://www.percona.com/doc/percona-xtrabackup/2.3/backup_scenarios/incremental_backup.html
- innodb_force_recovery: https://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html
- Percona-tools: https://www.percona.com/software/database-tools/percona-toolkit
- Mysqltuner: http://mysqltuner.pl
- Percona monitoring plugins: https://www.percona.com/doc/percona-monitoring-plugins/LATEST/index.html