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?

MySQLの外部アクセスを試してみた

Posted at

この記事では、

で作成した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

いじょう

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?