本實驗創(chuàng)建一個 Amazon EC2 實例和一個 Amazon RDS for MySQL 數(shù)據(jù)庫實例。然后使用標(biāo)準(zhǔn) MySQL 客戶端從 EC2 實例訪問數(shù)據(jù)庫實例。

步驟 1:創(chuàng)建 EC2 實例
步驟 2:記下該實例的公有 IPv4 DNS 的值,以及密鑰對名稱的值
步驟 3:創(chuàng)建 MySQL 數(shù)據(jù)庫實例
3.1 選擇 Databases (數(shù)據(jù)庫),選擇 Create database (創(chuàng)建數(shù)據(jù)庫),并確保已選擇 Easy create (輕松創(chuàng)建)。
3.2 在配置中,選擇 MySQL,數(shù)據(jù)庫實例大小,選擇套餐。
3.3 在 DB instance identifier(數(shù)據(jù)庫實例標(biāo)識符),輸入 database-test1。主用戶名,輸入主用戶的名稱,然后設(shè)定主密碼。
3.4 創(chuàng)建數(shù)據(jù)庫
步驟:連接到 MySQL 數(shù)據(jù)庫實例
1.1 查看數(shù)據(jù)庫實例的端點(DNS 名稱)和端口號。
1.2 連接到創(chuàng)建的 EC2 實例
ssh -i location_of_pem_file ec2-user@ec2-instance-public-dns-name1.3 在創(chuàng)建的 EC2 實例上安裝 MySQL 客戶端程序
sudo dnf update -y
sudo dnf install mariadb1051.4 連接到 MySQL 數(shù)據(jù)庫實例
mysql -h endpoint -P 3306 -u admin -p1.5 運行 SQL 命令
SELECT CURRENT_TIMESTAMP;