0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VagrantとVirtualBOXで構築したCentOS7環境のMySQL5.7のデータベースに、ローカル環境からアクセスする

0
Last updated at Posted at 2019-05-10

開発環境

・MacOS mojave 10.14.4
・MySQL5.7
・CentOS7

はじめに

・ローカル環境のデータベースと仮想環境のMySQLのデータベースの値を同じにします。
・ローカルにはMySQLをインストールしてません。仮想環境のみにMySQLをインストールしてます。

ローカル環境のデータベース

ローカル環境のデータベースとは、Rails 5.2.3のデータベースです。

database.yml
default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: password
  host: hostnumber
  #socket: /var/lib/mysql/mysql.sock


development:
  <<: *default
  database: databasename

①vagrantとVirtualBOXでCentOS7環境を構築

参照記事:https://wemo.tech/1564

②vagrantでMySQL5.7のデータベースを作成

参照記事:https://enomotodev.hatenablog.com/entry/2016/09/01/225200

③root権限付与

GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

参照記事:https://qiita.com/PallCreaker/items/0b02c5f42be5d1a14adb

④ローカル環境からCentOS7のMySQLにログイン

ローカル環境でデータベースを作成した時と同じhostnumber,passwordを使う。
databasenameも、ローカル環境でデータベースを作成したdatabasename=CentOS7上で作成したMySQLのdatabasenameの関係になるようにする

参照記事:http://mysql.javarou.com/dat/000389.html

$ mysql -hhostnumber -u root  -ppassword
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

$ ls init* inittable.sql`
$ mysql -hhostnumber -u root  -ppassword databasename < inittable.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.

これでローカル環境からCentOS7環境のデータベースにアクセスできた。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?