This shows you the differences between two versions of the page.
— | mariadb [2019/10/21 18:25] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== System variables ====== | ||
+ | [[https:// | ||
+ | |||
+ | ====== Performance report ====== | ||
+ | < | ||
+ | |||
+ | ====== Find duplicates ====== | ||
+ | < | ||
+ | GROUP BY udalostid, | ||
+ | |||
+ | ====== Remove duplicates by index ====== | ||
+ | < | ||
+ | |||
+ | ====== CVE-2016-6662 ====== | ||
+ | Attaker must have user access to gain access.\\ | ||
+ | How to block: Configuration files must be read-only for MySQL processes. | ||
+ | < | ||
+ | chown root:root / | ||
+ | chown root:root / | ||
+ | </ | ||
+ | |||
+ | ====== Some configuration chaos ====== | ||
+ | < | ||
+ | innodb_use_sys_malloc = 0 | ||
+ | innodb_buffer_pool_size = 1024MB | ||
+ | innodb_log_file_size = 50MB | ||
+ | innodb_checksum = 0 | ||
+ | innodb_doublewrite = 0 | ||
+ | innodb_flush_log_at_trx_commit = 2 | ||
+ | innodb_flush_method = O_DIRECT | ||
+ | innodb_file_format = Barracuda | ||
+ | innodb_file_format_check = Barracuda | ||
+ | innodb_file_per_table = 1 | ||
+ | |||
+ | innodb_open_files = 500 | ||
+ | innodb_thread_concurrency = 8 | ||
+ | innodb_lock_wait_timeout = 500 | ||
+ | interactive_timeout = 20 | ||
+ | back_log = 75 | ||
+ | table_cache = 300 | ||
+ | thread_cache = 32 | ||
+ | thread_concurrency = 8 | ||
+ | wait_timeout = 30 | ||
+ | connect_timeout = 10 | ||
+ | </ | ||
+ | |||
+ | Note that using CHAR will only speed up your access if the whole record is fixed size. That is, if you use any variable size object, you might as well make all of them variable size. You gain no speed by using a CHAR in a table that also contains a VARCHAR. | ||
+ | |||
+ | ====== Indexes ====== | ||
+ | ^ Query ^ Action ^ | ||
+ | | WHERE a = ? | create index (a) | | ||
+ | | ORDER BY a | create index (a) | | ||
+ | | GROUP BY a | index (a) | | ||
+ | | WHERE a = ? AND b = ? | create index (a, b) or (b, a) | | ||
+ | | ORDER BY a, b | create index (a, b) | | ||
+ | | WHERE a = ? ORDER BY b | create index (a, b) | | ||
+ | | WHERE a = ? OR b = ? | create separate (a) (b) | | ||
+ | | index (a, b) exist? | index (a) not neccesary | | ||
+ | | index (a) you need (a, b) | drop (a) and create (a, b) | | ||
+ | | index (a, b) you need (b) | create (b) | | ||
+ | |||
+ | **Be sure to check collate for each table, because DB can't use indexes.** | ||
+ | |||
+ | ====== Files manipulation ====== | ||
+ | < | ||
+ | <?php | ||
+ | /** Třída pro použití funkcí stream_wrapper_register() zapisující do databáze | ||
+ | * @copyright Jakub Vrána, https:// | ||
+ | */ | ||
+ | class StreamDB { | ||
+ | static $table = " | ||
+ | protected $id, $data = "", | ||
+ | function stream_open($path, | ||
+ | $url = parse_url($path); | ||
+ | $this-> | ||
+ | if ($mode == " | ||
+ | if ($this-> | ||
+ | mysql_query(" | ||
+ | } else { | ||
+ | mysql_query(" | ||
+ | $this-> | ||
+ | } | ||
+ | } elseif ($mode == " | ||
+ | mysql_query(" | ||
+ | } else { | ||
+ | $row = mysql_fetch_row(mysql_query(" | ||
+ | if (!$row) { | ||
+ | return false; | ||
+ | } | ||
+ | $this-> | ||
+ | } | ||
+ | return true; | ||
+ | } | ||
+ | function stream_close() { | ||
+ | $this-> | ||
+ | } | ||
+ | function stream_read($count) { | ||
+ | $this-> | ||
+ | return substr($this-> | ||
+ | } | ||
+ | function stream_write($data) { | ||
+ | mysql_query(" | ||
+ | return strlen($data); | ||
+ | } | ||
+ | function stream_eof() { | ||
+ | return ($this-> | ||
+ | } | ||
+ | function stream_flush() { | ||
+ | } | ||
+ | function stream_stat() { | ||
+ | return array(" | ||
+ | } | ||
+ | function unlink($path) { | ||
+ | $url = parse_url($path); | ||
+ | mysql_query(" | ||
+ | return mysql_affected_rows(); | ||
+ | } | ||
+ | function rename($path_from, | ||
+ | $url_from = parse_url($path_from); | ||
+ | $url_to = parse_url($path_to); | ||
+ | return mysql_query(" | ||
+ | } | ||
+ | function url_stat($path, | ||
+ | return array(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | stream_wrapper_register(" | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | ====== Usage ====== | ||
+ | < | ||
+ | copy(" | ||
+ | rename(" | ||
+ | copy(" | ||
+ | unlink(" | ||
+ | ?></ | ||
+ | |||
+ | ====== WGS84 distance ====== | ||
+ | < | ||
+ | DELIMITER $$ | ||
+ | |||
+ | CREATE | ||
+ | FUNCTION `gps_distance`(lat1 FLOAT,lng1 FLOAT,lat2 FLOAT,lng2 FLOAT) | ||
+ | RETURNS FLOAT | ||
+ | BEGIN | ||
+ | |||
+ | SET lat1 = lat1 * pi() / 180; | ||
+ | SET lng1 = lng1 * pi() / 180; | ||
+ | SET lat2 = lat2 * pi() / 180; | ||
+ | SET lng2 = lng2 * pi() / 180; | ||
+ | |||
+ | RETURN acos | ||
+ | ( | ||
+ | + cos(lat1)*sin(lng1)*cos(lat2)*sin(lng2) | ||
+ | + sin(lat1)*sin(lat2) | ||
+ | ) * 6372.795; | ||
+ | |||
+ | END$$ | ||
+ | |||
+ | DELIMITER ; | ||
+ | </ | ||
+ | |||
+ | ====== Bring back relax no-strict SQLmode ====== | ||
+ | < | ||
+ | SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,' | ||
+ | </ | ||
+ | |||
+ | ====== Install Debian ====== | ||
+ | |||
+ | < | ||
+ | < | ||