環境CentOS Linux release 7.3.1611 (Core)
インストール
# yum install mariadb mariadb-server mariadb-client
起動
起動する。
# systemctl start mariadb
自動起動設定
# systemctl enable mariadb
文字コードの設定
/etc/my.cnfにcharacter-set-server=utf8を追加する。
# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
character-set-server=utf8 ・・・・・(追加)
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
初期設定
初期セットアップコマンド mysql_secure_installationを用いる。
# mysql_secure_installation
Enter current password for root (enter for none):Enter
...中略...
Set root password? [Y/n] Y
...中略...
New password: 新しいパスワード
Re-enter new password: 新しいパスワード
...中略...
Remove anonymous users? [Y/n] Y
...中略...
Disallow root login remotely? [Y/n] Y
...中略...
Remove test database and access to it? [Y/n] Y
...中略...
Reload privilege tables now? [Y/n] Y
...中略...
Thanks for using MariaDB!
ユーザー作成
まずrootでログインする。
# mysql -u root -p
Enter password:作成したパスワード
ログインすると以下のような対話モードになる。
MariaDB [(none)]>
ここに、SQL文で対話ができる。最後に「;」をつけるのを忘れずに。
以下のSQL文はユーザを作成する例である。
MariaDB [(none)]> grant all on データベース名.テーブル名 to ユーザ名@localhost identified by 'パスワード';
grantは権限を設定するコマンドである。文法は次のように書く。
grant <権限> on <権限を設定する場所> to <権限を設定するユーザ>
<権限>にはallですべての権限を与え、細かく設定するには、SELECT,INSETのように、コマンド,コマンド,コマンド,...のように書く。<権限を設定する場所>はデータベース名.テーブル名のように書く。またワイルドカードを用いて、データベース名.*や*.*のようにも書ける。<権限を設定するユーザ>はユーザ名@ホスト名のように書く。ローカルホストで使用する場合はユーザ名@localhostで良い。
また、ユーザの後ろにidentified by 'パスワード'を加えることでパスワードを設定できる。
ユーザー名とホスト名の一覧を見たいときは以下のコマンドを実行する。
MariaDB [(none)]> select user,host from mysql.user;
詳しい説明はselectについて説明するときにする。
...
....
.....
......
飽きた....。