#author("2021-06-11T10:29:51+09:00","default:ham","ham") #author("2021-06-11T10:30:11+09:00","default:ham","ham") #amazon(4797369450) #contents #br #adsense(728x90) #br * 概要 [#i55044fd] - GTID [Global Transaction ID] -- -- '''domain_id-server_id-transaction_no''' - gtid_slave_pos * インストール [#gb2925e8] ** パッケージ インストール [#q02fcb9d] + レポジトリの追加 #pre(soft){{ host# vi /etc/yum.repos.d/MariaDB.repo # MariaDB 10.0 CentOS repository list - created 2014-02-04 14:23 UTC # http://mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.0/centos6-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 }} + 公開鍵のインストール #pre(soft){{ host# rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB }} + MariaDB のインストール #pre(soft){{ host# yum install MariaDB-server MariaDB-client }} ** 初期設定 [#e3f6fd68] #pre(soft){{ host# mysql_secure_installation /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables 2014-02-07 (金) 03:02:02 [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB! }} #pre(soft){{ host# vi /etc/my.cnf.d/server.cnf [mysqld] character-set-server = utf8 plugin-load = handlersocket.so }} * ログイン [#adcc1557] #pre(soft){{ # mysql ['''option'''] }} -- '''option''' |オプション|意味|説明|h |-u '''username'''|user|ユーザー名を指定する (デフォルトは OS のユーザー名)| |-p|password|パスワードを入力する| |-h '''hostname'''|host|リモートの Maria DB に接続する| - ローカル #pre(soft){{ # mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 17 Server version: 10.0.7-MariaDB MariaDB Server Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> }} - リモート #pre(soft){{ # mysql -u root -p -h '''hostname''' }} - リモート (SSL) #pre(soft){{ # mysql -u root -p -h '''hostname''' --ssl-ca=/etc/ssl/certs/ca-bundle.crt }} * ユーザー [#adbc5502] - ユーザー情報は mysql.user テーブルで管理されている ** 一覧 [#k7b49b28] #pre(soft){{ MariaDB [(none)]> SELECT Host, User FROM mysql.user; }} ** 作成 [#d86e5017] #pre(soft){{ MariaDB [(none)]> CREATE USER ''''username''''@''''hostname'''' IDENTIFIED BY [PASSWORD] ''''password''''; }} ** パスワード変更 [#w12206f9] #pre(soft){{ MariaDB [(none)]> SET PASSWORD FOR '''username'''@"'''hostname'''"=PASSWORD(''''password''''); }} ** 削除 [#x4ec9746] #pre(soft){{ MariaDB [(none)]> DELETE FROM mysql.user WHERE user=''''username''''; }} * 権限 [#jeca8a7c] ** デフォルト [#n54f16e1] #pre(soft){{ MariaDB [(none)]> show grants for 'user'@'%'; +-------------------------------------------------------------------------------------------------------+ | Grants for user@* | +-------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO `user`@`%` IDENTIFIED BY PASSWORD '*P65MZZ4BN5L0T4CHHBP0OIEEQFE3MPI3RQKB2T6O' | +-------------------------------------------------------------------------------------------------------+ }} * データベース [#e2ecd9fb] ** 一覧 [#fb6d8c3c] #pre(soft){{ MariaDB [(none)]> show databases; }} ** 作成 [#y37cd2fe] #pre(soft){{ MariaDB [(none)]> create database '''db-name'''; }} ** 削除 [#j6a72ca4] #pre(soft){{ MariaDB [(none)]> drop database '''db-name'''; }} ** データベースの選択 [#ea618d37] #pre(soft){{ MariaDB [(none)]> use testdb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A &color(yellow){Database changed}; MariaDB [testdb]> }} * テーブル [#dc5e395f] MariaDB [testdb]> ** 一覧 [#c3ac0f29] #pre(soft){{ MariaDB [(testdb)]> show tables; }} ** 作成 [#j12efdaf] #pre(soft){{ MariaDB [(testdb)]> }} ** 削除 [#a2a7aeee] #pre(soft){{ MariaDB [(testdb)]> }} ** 中身だけ削除 [#k869fc5a] #pre(soft){{ MariaDB [(testdb)]> TRUNCATE TABLE table-name; }} ** 定義 [#j285e5a0] #pre(soft){{ MariaDB [(testdb)]> show columns from table-name; }} * レプリケーション [#q87afcfd] ** 設定 [#qf1edf09] - Master の定義 #pre(soft){{ MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST=''''ip-addr'''', MASTER_USER=''''repuser'''', MASTER_PASSWORD=''''passwd''''; }} - Master のデータをリストア #pre(soft){{ # mysql -u root -p < backup.dump }} - レプリケーションの開始 #pre(soft){{ MariaDB [(none)]> START SLAVE; }} ** 停止 [#x296cf14] #pre(soft){{ MariaDB [(none)]> STOP SLAVE; MariaDB [(none)]> RESET SLAVE ALL; }} * バックアップ & リストア [#k890a7e1] #pre(soft){{ # mysqldump ['''option'''] ['''db-name''' ['''tbl-name''']] > filename }} -- '''option''' |>|オプション|説明|h |--user='''username'''|-u '''username'''|| |--password[='''password''']|-p['''password''']|| |--password[='''passwd''']|-p['''passwd''']|| |||| |--databases '''db-name''' ['''db-name'''...]|-B|特定のデータベースをバックアップする&br;--databases は省略可| |--all-databases|-A|全てのデータベースをバックアップする| |--opt||--add-drop-table --add-locks --create-options --disable-keys --extended-insert&br;--lock-tables --quick --set-charset (デフォルトで有効)| | --add-drop-table||| | --add-locks||| | --create-options||| | --disable-keys||| | --extended-insert||| | --lock-tables|-l|ダンプ前に全テーブルをロックする (DB 毎にロックされるため、DB 間の整合性は保たれない)&br;InnoDB では --single-transaction を使う| | --quick||| | --set-charset||| |--skip-lock-tables||デフォルトで有効になっている --lock-tables を無効化| |--lock-all-tables|-x|ダンプ中、全データベースの全テーブルをロックする (--single-transaction、--lock-tablesは向こうになる)| |--single-transaction||ダンプを 1 トランザクションで行う (ロックなしで整合性を保つ)| |--master-data||CHANGE MASTER TO 句を含める (スレーブサーバがマスターサーバのバイナリログの読み取り開始ポイントを知ることが出来る)&br;--single-transaction 有効時はダンプ開始時に一瞬グローバルリードロックされる| |--master-data=2||バイナリログの読み出し開始位置をコメントとして出力する。| |--default-character-set||| -- '''db-name''' --- 特定のデータベースをバックアップする * その他 [#wfb49759] ** システム変数 [#l8a8cefe] #pre(soft){{ MariaDB [(none)]> SHOW VARIABLES; }} #pre(soft){{ MariaDB [(none)]> SHOW VARIABLES LIKE "char%"; }} #pre(soft){{ MariaDB [(none)]> SHOW VARIABLES LIKE 'slow%'; }} ** バージョン情報 [#s78b22c1] #pre(soft){{ MariaDB [(none)]> SELECT VERSION(); +-----------------+ | VERSION() | +-----------------+ | 10.3.17-MariaDB | +-----------------+ 1 row in set (0.000 sec) }} #br #adsense(728x90) #br