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 1 year has passed since last update.

【VirtualBox】CentOS7にMySQL8.0を入れる方法

Posted at

概要

ローカルの開発環境として、VirtualBox上のCentOS7にMySQL8.0を入れてWindows上のIDEから接続できるようにする

環境

  • Windows10
  • VirtualBox 6.1
    • CentOS Linux release 7.7.1908 (Core)
    • mysql Ver 8.0.18 for Linux on x86_64 (MySQL Community Server - GPL)

手順

yum installでMySQLを入れる

// パッケージ追加、確認
$ sudo yum localinstall http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
$ yum info mysql-community-server

// インストール、確認
$ sudo yum install mysql-community-server
$ mysql --version
mysql  Ver 8.0.18 for Linux on x86_64 (MySQL Community Server - GPL)

WindowsからCentOSのMySQLに接続できるように

firewallでTCP3306(MySQLの接続port)を許可します。

$ sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
$ sudo firewall-cmd --reload
$ sudo firewall-cmd --list-all | grep port
  ports: 3306/tcp
  forward-ports: 
  source-ports:

MySQLに接続用のユーザーを追加

MySQLにrootユーザーでログインしてまずは初期パスワードを変更します。次に接続用ユーザーを追加して権限を付与します。

// rootユーザーの初期パスワード変更
mysql> alter user 'root'@'localhost' identified BY 'NewPassword';

// 接続用ユーザーを追加、権限付与
mysql> create user 'user-name'@'%' identified by 'your-password';
mysql> grant all privileges on *.* to 'user-name'@'%' with grant option;
mysql> flush privileges;

// 確認
mysql> select user, host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| user-name        | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+

ちなみに、パスワードはデフォルトだと英数字記号(英字は大文字と小文字)をそれぞれ1つ以上使わないと引っかかると思います。

// パスワードポリシーの確認
mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.00 sec)

接続情報を確認

IPアドレスを確認し、データソースに接続情報を記載して無事に接続完了です。

// IPアドレスを確認
$ ip a

// データソースに接続情報を記載(Java:SpringBootの例)
datasource:
  url: jdbc:mysql://192.168.1.123:3306/your_db
  username: user-name
  password: your-password

参考

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?