简体   繁体   English

在 Google Cloud Compute Engine 虚拟机实例上设置 MySQL

[英]Setting up MySQL on a Google Cloud Compute Engine VM instance

I've been moving my site from GoDaddy to Google Cloud and I'm very close to being able to launch.我一直在将我的网站从 GoDaddy 转移到 Google Cloud,而且我非常接近能够启动。 The only missing piece is setting up the database.唯一缺少的部分是设置数据库。

I've already installed MySQL on the server and when I run sudo service mysql status , it says that mariadb.service is active (running) and "Taking your SQL requests now..."我已经在服务器上安装了 MySQL,当我运行sudo service mysql status ,它说mariadb.service处于活动状态(正在运行)和“现在接受你的 SQL 请求......”

I also added the VM instance's IP address to the SQL instance's Connections.我还将 VM 实例的 IP 地址添加到 SQL 实例的连接中。

However, when I try to connect on the live site, I get a php error that reads:但是,当我尝试在实时站点上进行连接时,出现一个 php 错误,内容为:

PHP Fatal error: Uncaught Error: Class 'mysql' not found in db.php:3 PHP 致命错误:未捕获的错误:在 db.php:3 中找不到类“mysql”

Am I missing a setup step?我是否缺少设置步骤? I followed all of Google's tutorials and help files about this and don't understand what I'm missing.我遵循了 Google 的所有教程和关于此的帮助文件,但不明白我错过了什么。

I installed the libraries with these commands:我使用以下命令安装了库:

sudo apt-get update

sudo apt-get install apache2 php libapache2-mod-php

sudo apt-get install mysql-server

sudo apt-get install mysql-client

I'm trying to connect with this string in my php code:我试图在我的 php 代码中连接这个字符串:

$dbcon=@new mysql('[SQL instance IP address]','[DB username]','[DB password]','[DB name]');

To solve this problem, do three things:要解决这个问题,要做三件事:

1) Install the PHP MySQL Extensions: 1) 安装 PHP MySQL 扩展:

sudo apt-get install php7.0-mysqlnd

2) Make sure that the extension is enabled in your php.ini file. 2) 确保在php.ini文件中启用了扩展。 There will be one for the PHP interpreter and another one for the Apache web server.将有一个用于 PHP 解释器,另一个用于 Apache Web 服务器。

3) Change your code to not use the mysql class and use mysqli instead: 3) 将代码更改为不使用mysql类,而是使用mysqli

$dbcon = new mysqli('localhost', $db_username, $db_password, $db_name);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Cloud Run PHP 连接到 Google Cloud Compute Engine 虚拟机上的 MySQL 实例 - Connect to MySQL instance on Google Cloud Compute Engine VM from Cloud Run PHP 500(内部服务器错误)在 Google Cloud 中托管 Web - Compute Engine VM + Firestore + PHP + Apache2 - 500 (Internal Server Error) Hosting Web in Google Cloud - Compute Engine VM + Firestore + PHP + Apache2 使用htaccess的apache与谷歌计算引擎vm - google compute engine vm with apache using htaccess 无法在Google Cloud Compute引擎实例中获得访问者的公共IP(已创建容器集群) - Cannot get visitor's public IP in Google Cloud Compute engine instance (container cluster created) 使用云sql作为数据库连接网站计算引擎VM - connect website compute engine VM using cloud sql as database 要获得 mysql 查询的快速结果,需要升级 Google SQL CLOUD 或 Google COMPUTE Engine - To get fast result of mysql queries what should be need to upgrade either Google SQL CLOUD or Google COMPUTE Engine PHP MySQL PDO 连接到 Google Cloud Z9778840A0100CB30C9822876741B0B 实例不工作 - PHP MySQL PDO Connection to Google Cloud SQL Instance from VM Instance not working Google Cloud Console 虚拟机实例上的 Apache 服务器 - Apache Server on Google Cloud Console VM Instance 为什么google cloud vm实例的lamp stack中的mysql会返回错误的查询结果? - Why does mysql in lamp stack on google cloud vm instance return wrong query results? 从Google Compute Engine是否可以连接到Google Cloud Storage? - Is there anyway to connect to Google Cloud Storage from Google Compute Engine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM