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
host# rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
host# yum install MariaDB-server MariaDB-client
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!
host# vi /etc/my.cnf.d/server.cnf [mysqld] character-set-server = utf8 plugin-load = handlersocket.so
# mysql [option]
オプション | 意味 | 説明 |
-u username | user | ユーザー名を指定する (デフォルトは OS のユーザー名) |
-p | password | パスワードを入力する |
-h hostname | host | リモートの Maria DB に接続する |
# 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)]>
# mysql -u root -p -h hostname
# mysql -u root -p -h hostname --ssl-ca=/etc/ssl/certs/ca-bundle.crt
MariaDB [(none)]> SELECT Host, User FROM mysql.user;
MariaDB [(none)]> CREATE USER 'username'@'hostname' IDENTIFIED BY [PASSWORD] 'password';
MariaDB [(none)]> SET PASSWORD FOR username@"hostname"=PASSWORD('password');
MariaDB [(none)]> DELETE FROM mysql.user WHERE user='username';
MariaDB [(none)]> show grants for 'user'@'%'; +-------------------------------------------------------------------------------------------------------+ | Grants for user@* | +-------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO `user`@`%` IDENTIFIED BY PASSWORD '*P65MZZ4BN5L0T4CHHBP0OIEEQFE3MPI3RQKB2T6O' | +-------------------------------------------------------------------------------------------------------+
MariaDB [(none)]> show databases;
MariaDB [(none)]> create database db-name;
MariaDB [(none)]> drop database db-name;
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
Database changed
MariaDB [testdb]>
MariaDB [testdb]>
MariaDB [(testdb)]> show tables;
MariaDB [(testdb)]>
MariaDB [(testdb)]>
MariaDB [(testdb)]> TRUNCATE TABLE table-name;
MariaDB [(testdb)]> show columns from table-name;
MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='ip-addr', MASTER_USER='repuser', MASTER_PASSWORD='passwd';
# mysql -u root -p < backup.dump
MariaDB [(none)]> START SLAVE;
MariaDB [(none)]> STOP SLAVE; MariaDB [(none)]> RESET SLAVE ALL;
# mysqldump [option] [db-name [tbl-name]] > filename
オプション | 説明 | |
--user=username | -u username | |
--password[=passwd] | -p[passwd] | |
--databases db-name [db-name...] | -B | 特定のデータベースをバックアップする --databases は省略可 |
--all-databases | -A | 全てのデータベースをバックアップする |
--opt | --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset (デフォルトで有効) | |
--add-drop-table | ||
--add-locks | ||
--create-options | ||
--disable-keys | ||
--extended-insert | ||
--lock-tables | -l | ダンプ前に全テーブルをロックする (DB 毎にロックされるため、DB 間の整合性は保たれない) 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 句を含める (スレーブサーバがマスターサーバのバイナリログの読み取り開始ポイントを知ることが出来る) --single-transaction 有効時はダンプ開始時に一瞬グローバルリードロックされる | |
--master-data=2 | バイナリログの読み出し開始位置をコメントとして出力する。 | |
--default-character-set |
MariaDB [(none)]> SHOW VARIABLES;
MariaDB [(none)]> SHOW VARIABLES LIKE "char%";
MariaDB [(none)]> SHOW VARIABLES LIKE 'slow%';
MariaDB [(none)]> SELECT VERSION(); +-----------------+ | VERSION() | +-----------------+ | 10.3.17-MariaDB | +-----------------+ 1 row in set (0.000 sec)