MySQL连接不工作在AWS EC2 [英] Mysql connection is not working on AWS EC2
问题描述
我已经尝试配置AWS服务器自己。
I have trying to configure AWS server myself.
信息1: EC2托管和选择Ubuntu的14操作系统和安装Apache PHP和我已经检查它PHP和HTTP的作品。我有Apache和PHP使用下面安装 命令:
Info1: EC2 as hosting and select Ubuntu 14 as OS and install Apache PHP and I have check that it php and http works. I have install Apache and php using below command:
sudo apt-get install apche2 php5 libapche2-mod-php5
和使用安装MySQL客户端
and install MySQL client using
sudo apt-get install mysql-client-core-5.5
信息2: RDS为MySQL数据库实例,它正在
Info2: RDS as mysql database instance it is working.
INFO3:当我们试图用命令将其工作从EC2服务器导入SQL
Info3: When we trying to import sql from EC2 server using command it work
Info4: t2.micro的EC2实例和t2.micro为RDS实例
Info4: t2.micro as EC2 Instance and t2.micro as RDS instance
问题:
当我们试图连接的RDS从PHP脚本它示值误差:
When we try to connection RDS from a php script it showing error:
调用未定义功能mysqli_connect()在/var/www/html/awsmysql.php第3行
我的脚本code是:
<?php
echo "Create connection";
$con=mysqli_connect("awsmysqlhost","root","password1223","db");
echo "Check connection";
try{
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "Create database";
$sql="Select * from test";
if (mysqli_query($con,$sql)) {
$result = mysqli_query($con,"Select * from test");
while($row = mysqli_fetch_array($result)) {
echo $row['id'] . " " . $row['name'];
echo "<br>";
}
echo "Database my_db created successfully";
// var_dump($r);
} else {
echo "Error creating database: " . mysqli_error($con);
}
}catch(Exception $e)
{
echo "<pre>";
var_dump($e);
echo "</pre>";
}
?>
问题(S):
Question(s):
-
时,需要安装一些MySQL或PHP来库,将连接EC2具有RDS和运行的系统?
Is need to install some MySQL or PHP to library which will connect EC2 with RDS and running the system?
需要一些Apache配置的EC2实例?
Need some Apache Configuration at EC2 Instance?
有没有需要一些设置在AWS?
Is there need some setting at AWS?
推荐答案
请安装PHP扩展MySQL的。运行以下命令,然后再试。
Please install php extension for mysql. Run below command and then try.
apt-get install php5-mysql
这篇关于MySQL连接不工作在AWS EC2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!