前回: ゼロからphp7環境構築 - 0.事前準備
次回: ゼロからphp7環境構築 - 2.Appサーバー設定
概要
今回はDBサーバーの設定を行います
前回作成・追加したBOX(centos72)に、php7からデフォルトになったmariaDBをインストールします。MySQLとほぼ一緒です
もくじ
- 作業フォルダ作成
- vagrant init
- Vagrantfile 編集
- vagrant up
- mariaDB インストール
- 起動, 自動起動設定
- テスト接続
作業フォルダ作成
C:\HashiCorp\Vagrant 以下に作業フォルダを作成します
(windowsでの作業には PowerShell を使用しています)
cd C:\HashiCorp\Vagrant\work\testProject
mkdir dbserver
vagrant init
cd dbserver
vagrant init centos72
Vagrantfile 編集
変更前
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
変更後
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.33.21"
vagrant up
vagrant up
192.168.33.21 (vagrant / vagrant) へssh接続
mariaDB インストール
インストール済みを削除
sudo yum remove mariadb mariadb-libs
rpm -qa | grep -i "mariadb"
※何も表示されなかったら OK
インストール元の追加
sudo vim /etc/yum.repos.d/MariaDB.repo
編集内容
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
インストール
sudo yum -y install --enablerepo=mariadb MariaDB-common MariaDB-devel MariaDB-shared MariaDB-compat MariaDB-server MariaDB-clien
起動, 自動起動設定
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
テスト接続
mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.19-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases; // DB一覧表示
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
MariaDB [(none)]> use test; // 使用するDB指定
MariaDB [test]> show tables; // テーブル一覧表示
Empty set (0.00 sec) // テーブルなし
MariaDB [test]> CREATE TABLE sample (id int auto_increment, name varchar(30), index(id)); // テーブル作成
Query OK, 0 rows affected (0.01 sec)
MariaDB [test]> show tables; // テーブル一覧表示
+----------------+
| Tables_in_test |
+----------------+
| sample |
+----------------+
MariaDB [test]> desc sample; // テーブル定義表示
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | MUL | NULL | auto_increment |
| name | varchar(30) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
MariaDB [test]> insert into sample (name) values ('Yamada Taro'); // レコード追加
MariaDB [test]> insert into sample (name) values ('Tanaka Hanako');
MariaDB [test]> select * from sample; // 確認
+----+---------------+
| id | name |
+----+---------------+
| 1 | Yamada Taro |
| 2 | Tanaka Hanako |
+----+---------------+
2 rows in set (0.00 sec)
MariaDB [test]> exit
Bye