从零开始搭建PHP7环境- 1.设置DB服务器

上一篇:从零开始搭建PHP7环境 – 0.准备工作
下一篇:从零开始搭建PHP7环境 – 2.应用服务器配置

简而言之

这次我们将进行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

创建流浪者初始化文件

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

连接到192.168.33.21的ssh(使用vagrant / vagrant作为凭据)。

安装 MariaDB。

删除已安装

sudo yum remove mariadb mariadb-libs

rpm -qa | grep -i "mariadb"
※何も表示されなかったら OK

添加源文件进行安装

sudo vim /etc/yum.repos.d/MariaDB.repo

编辑内容

[mariadb]
名称 = MariaDB
基URL = http://yum.mariadb.org/10.1/centos7-amd64
gpg密钥 = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpg校验 = 1

安装

sudo yum -y install –enablerepo=mariadb MariaDB-common MariaDB-devel MariaDB-shared MariaDB-compat MariaDB-server MariaDB-client

参考: 在 CentOS 7 上安装并进行 MariaDB 的初始设置

启动,自动启动设置

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

上回:从零开始搭建PHP7环境 – 0.前期准备
下回:从零开始搭建PHP7环境 – 2.应用服务器设置

bannerAds