この記事では、
で作成したOCIコンピュート上のMySQLへの外部アクセスを試してみます。
新規ユーザを作成(接続対象ユーザが未作成の場合):
create user 'testuser'@'%' identified by 'WelCome123#123#';
- 外部アクセスのIPを絞る場合は「%」部分に任意のアドレスを指定する
新規ユーザに権限を付与する:
grant all privileges on *.* to 'testuser'@'%';
OSのfirewallでポートを許可する:
sudo firewall-cmd --permanent --add-port=3306/tcp
sudo firewall-cmd --reload
確認:
sudo firewall-cmd --list-ports
[opc@mysqlsource ~]$ sudo firewall-cmd --list-ports
3306/tcp
別の環境から外部接続を試す:
mysql -h <コンピュートのIPアドレス> --port <ポート番号> -u <ユーザ名> -p
[opc@mysqltarsrv ~]$ mysql -h 10.0.0.5 --port 3306 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 8.4.3 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
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.
mysql>
接続確認コマンド:
mysqladmin ping -h 10.0.0.5 --port 3306 -u root -p
[opc@mysqltarsrv ~]$ mysqladmin ping -h 10.0.0.5 --port 3306 -u root -p
Enter password:
mysqld is alive
いじょう