備忘録

備忘録

MariaDB

MariaDBでslow_queryログを出力する方法

Ⅰ. はじめ タイトルの通り「MariaDBでslow_queryログを出力する方法」です。 Ⅱ. 手順 1. ファイルを編集する /etc/mysql/mariadb.conf.d/50-server.cnf [mysqld] slow_query_log=1 # slow_queryログ出力を有効にする long_query_time=5 # 5秒以上かかるクエ…

MariaDBのDBを高速にバックアップ/リストアする方法

Ⅰ. はじめに 本記事ではmysqldumpの代わりにmariabackupを使用することで高速化を狙います Ⅱ. 手順 1. qpressをインストールする wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb dpkg -i percona-release_latest.$(l…

MariaDBでレプリケーションする方法

Ⅰ. はじめに タイトルの通り「MariaDBでレプリケーションする方法」です。 Ⅱ. やり方 1. Master側の設定を変更する server.cnf [mysqld] server-id = 1 log-bin expire_logs_days = 3 max_binlog_size = 500M 2. Master側のDBをダンプする mysqldump -u root…

MariaDBでn~mの範囲のランダムな数値を取得する方法

Ⅰ. はじめに タイトルの通り「MariaDBでn~mの範囲のランダムな数値を取得する方法」です。 Ⅱ. やり方 基本形 select round((rand() * (max-min))+min) 0~10 select round((rand() * (10))) 1~10 select round((rand() * (9))+1) 2~5 select round((rand(…

Node.jsでMariaDB, MySQLを扱う方法

Ⅰ. はじめに Ⅱ. やり方 1. 必要なパッケージをインストールする 2. サンプルプログラムを書く 実行結果 参考 その他 Ⅰ. はじめに タイトルの通り「Node.jsでMariaDB, MySQLを扱う方法」です。 Ⅱ. やり方 1. 必要なパッケージをインストールする npm install …

PythonでFlask + MariaDB(MySQL)を使う方法

Ⅰ. はじめに タイトルの通り「PythonでFlask + MariaDB(MySQL)を使う方法」です。 Ⅱ. やり方 1. Flaskをインストールする pip install flask pip install flask-mysql 2. サンプルプログラム from flask import Flask, jsonify from flaskext.mysql import M…

MariaDB(MySQL)を自動的にGoogleDriveにバックアップする方法

Ⅰ. はじめに タイトルの通り「MariaDB(MySQL)を自動的にGoogleDriveにバックアップする方法」です。 Ⅱ. やり方 1. git cloneする $ git clone https://github.com/kagasu/DBAutoBackup 2. gdriveを初期化する // gdrive を以下のリポジトリから自分でビルド…

MariaDBのデータ復旧方法

Ⅰ. はじめに MariaDBが停止し二度と起動しない状態となった場合、原因究明よりもとにかくデータを復旧したい場合のやり方です。 Ⅱ. やり方 1. innodb_force_recovery の値を設定する 1~6まで1ずつ値を起動するまで増やし、MariaDBが起動できるようになるま…

Python3でMariaDB(MySQL)に接続する方法

Ⅰ. はじめに タイトルの通り「Python3でMySQLに接続する方法」です。 Ⅱ. やり方 1. 必要なものをインストールする CentOS 7.4の場合 yum -y install gcc mariadb-devel MariaDB-shared zlib-devel openssl-develUbuntu 16.04の場合 apt -y install build-ess…

MariaDB Host 'x.x.x.x' is blocked because of many connection errors

エラー全文は以下のとおりです。 Host 'x.x.x.x' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 一時的な対処法 エラー回数をリセットすることにより、一時的な対処を行います。 1) ブロックされていないホストから…

CentOS 7.2 MariaDB 外部接続を有効にする

環境 $ cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) $ mysql --version mysql Ver 15.1 Distrib 10.1.10-MariaDB, for Linux (x86_64) using readline 5.1※ MariaDBは以下の記事の通り導入しました。 http://d.hatena.ne.jp/kagasu/20160…

LinuxにMariaDBをインストールする方法

Ⅰ. はじめに Ⅱ. やり方 1. 以下コマンドを実行する 2. MariaDB をインストールする 3. MariaDBを起動する 4. 初期設定を行う 5. その他パラメータの設定 5. MariaDBを再起動する 参考 その他設定 Ⅰ. はじめに タイトルの通り「LinuxにMariaDBをインストール…