yum remove mariadb-libs
rm -rf /var/lib/mysql/
yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum info mysql-community-server
yum -y install mysql-community-server
sudo yum info mysql-community-server
sudo yum install mysql-community-server
警告: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-client-5.7.40-1.el7.x86_64.rpm: ヘッダー V4 RSA/SHA256 Signature、鍵 ID 3a79bd29: NOKEY
file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql から鍵を取得中です。
The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.
Failing package is: mysql-community-client-5.7.40-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
エラーが出たら
sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
mysqld --version
正常にインストールされていれば画像のように出力される。
sudo systemctl enable mysqld
sudo systemctl start mysqld
sudo systemctl status mysqld
正常に動いていれば以下のように出力される。
sudo cat /var/log/mysqld.log | grep root
root@localhost:
y5;yhhi*&ayP
mysql -u root -p
Enter password:
例
Enter password:y5;yhhi*&ayP
成功すると画像のようになる
パスワードの変更
大文字・小文字・数字・記号を混ぜて8文字以上であること
例として以下を使用
PassWord123!
set password = password('PassWord123!');
設定を変更するために、一度MySQLから抜ける
コマンドは以下
exit
設定ファイル
/etc/my.cnfに以下を設定ファイルの末尾に追記、サーバをリスタートする
vim /etc/my.cnf
移動後
/etc/my.cnfの末尾に追記
character_set_server=utf8
skip-character-set-client-handshake
記載後
保存して終了
:wq
サーバのリスタート
sudo systemctl restart mysqld
正常に動作しているか確認
sudo systemctl status mysqld
正常に動作していれば上記のように出力される。
動作確認
sudo firewall-cmd --add-service=mysql --zone=public --permanent
sudo systemctl restart firewalld
sudo systemctl status firewalld
外部からの接続を許可
mysql -u root -p
PassWord123!
grant all privileges on . to root@'12.7.%' identified by 'PassWord123!';
ユーザー覧表示する
SELECT Host, User FROM mysql.user;
上記で入力した
12.7.%が表示されていればOK
MySQL Workbenchインストール
MySQL Workbench のダウンロード用 Web ページを開く
https://dev.mysql.com/downloads/workbench/
「Download」をクリック
スロークエリログ設定
Oracle Web アカウントにサインアップ,ログイン
ダウンロードしたプログラムを実行
ようこそ画面
「Next」をクリック
種類の選択
「Complete」を選び, 「Next」をクリック
インストールの開始
「Install」をクリック
インストール終了の確認
MySQL Workbenchの起動と接続
SSH Hostname
127.0.0.1:3333
コロンより後ろの番号はVirtualBoxの各自で設定しているホストポートを記載
SSH Username
通常はvagrant, それぞれの環境に合わせてユーザー名を指定今回はroot
SSH Password
rootに変更する際に使用するパスワード記載
SSH Key File 鍵認証を利用しいている場合は指定
今回は記載しない
MySQL Hostname
localhostが127.0.0.1
MySQL Server Port
3306 そのまま
Username
MySQLにログインするときのユーザー名、rootとか
Password
MySQLにログイン際のパスワード、今回はPassWord123!
DefaultSchema
そのまま
全てを設定したら、Test Connethon をクリック
正常に接続できると、「Successfully made the MySQL connection」と表示される。
ダイアログを「OK」で閉じた後、設定画面をCloseをクリックして閉じる。
作成したものが、画面に表示される。
作成したものを選択すると以下の画面に遷移する
正常に動作するか確認
select * from sys.host_summary;
赤枠のボタンをクリック
結果が表示される
フォルダー選択ボタンをクリックしインポートしたいファイルを
正常にインポートされると、以下のようになる。
Query1をクリックし元の画面に戻る
SQLを実行
select * from world.city, world.country;
実行結果が正常に表示されれば成功
/etc/my.cnfに追記する
#slow query log
slow_query_log=1
long_query_time=1.0
log_queries_not_using_indexes=1
slow_query_log_file='slow_query.log'
1秒以上要するクエリとインデックスを利用しないクエリが、以下のディレクトリに出力される
/var/lib/mysql/slow_query.log