LoginSignup
9
15

More than 5 years have passed since last update.

MariaDBのインストールと起動

Last updated at Posted at 2017-07-09

環境CentOS Linux release 7.3.1611 (Core)

インストール

# yum install mariadb mariadb-server mariadb-client

起動

起動する。

# systemctl start mariadb

自動起動設定

# systemctl enable mariadb

文字コードの設定

/etc/my.cnfcharacter-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について説明するときにする。

...
....
.....
......
飽きた....。

9
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
15