微软 Azure 团队早就为 Web 开发者推出了一项名为“MySQL in-app”的新功能,便于他们使用 Azure 应用服务(App Service)创建调用 MySQL 数据库的 Web 应用。常见内容管理系统首先配置标准我们今天也给出:
WordPress 4+
Joomla 3+
Drupal 8+
Configuration Location
wwwroot/wp-config.php
wwwroot/configuration.php
wwwroot/sites/default/settings.php
Default Configuration
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘databaseName’);/** MySQL database username */
define(‘DB_USER’, ‘databaseUserName’);/** MySQL database password */
define(‘DB_PASSWORD’, ‘databasePassword’);/** MySQL hostname */
define(‘DB_HOST’, ‘databaseHostName’);
public $dbtype = ‘mysql’;
public $host = ‘databaseHostName’;
public $user = ‘databaseUserName’;
public $password = ‘databasePassword’;
public $db = ‘databaseName’;
public $dbprefix = ‘jos_’;
$databases[‘default’] [‘default’] = array (
‘database’ => ‘databasename’,
‘username’ => ‘sqlusername’,
‘password’ => ‘sqlpassword’,
‘host’ => ‘localhost’,
‘port’ => ‘3306’,
‘driver’ => ‘mysql’,
‘prefix’ => ”,
‘collation’ => ‘utf8mb4_general_ci’,);
MySQL In-App
Part 1 – Credentials
$connectstr_dbhost = ”;
$connectstr_dbname = ”;
$connectstr_dbusername = ”;
$connectstr_dbpassword = ”;foreach ($_SERVER as $key => $value) {
if (strpos($key, “MYSQLCONNSTR_localdb”) !== 0) {
continue;
}$connectstr_dbhost = preg_replace(“/^.*Data Source=(.+?);.*$/”, “\\1”, $value);
$connectstr_dbname = preg_replace(“/^.*Database=(.+?);.*$/”, “\\1”, $value);
$connectstr_dbusername = preg_replace(“/^.*User Id=(.+?);.*$/”, “\\1”, $value);
$connectstr_dbpassword = preg_replace(“/^.*Password=(.+?)$/”, “\\1”, $value);
}
WordPress 4+
Joomla 3+
Drupal 8+
MySQL In-App
Part 2 – Configuration
// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, $connectstr_dbname);
/** MySQL database username */
define(‘DB_USER’, $connectstr_dbusername);
/** MySQL database password */
define(‘DB_PASSWORD’, $connectstr_dbpassword);
/** MySQL hostname : this contains the port number in this format host:port.
/** Port is not 3306 when using this feature*/
define(‘DB_HOST’, $connectstr_dbhost);
public $dbtype = ‘mysql’;
public $host = DB_HOST;
public $user = DB_USER;
public $password = DB_PASSWORD;
public $db = DB_NAME;
public $dbprefix = ‘jos_’;
$databases[‘default’] [‘default’] = array (
‘database’ => $connectstr_dbname,
‘username’ => $connectstr_dbusername,
‘password’ => $connectstr_dbpassword,
‘prefix’ => ”,
‘host’ => $connectstr_dbhost,
‘port’ => $_SERVER[‘WEBSITE_MYSQL_PORT’] ,
‘driver’ => ‘mysql’,
‘namespace’ => ‘Drupal\\Core\\Database\\Driver\\mysql’,
‘collation’ => ‘utf8mb4_general_ci’,
);
“MySQL in-app”允许开发者在相同环境中并行运行 MySQL 服务器与其 Web 应用,进而在开发并测试使用 MySQL 的 PHP 应用时起到简化工作流程的效果。
MySQL 云数据库服务已登陆 Azure 平台,能够提供高可靠、高安全、高可用、高性价比的数据库,无需人工维护基础架构,即可在云端快速部署,进而降低企业运维成本。
“MySQL in-app(预览版)”功能简介:
支持多款使用 MySQL 的 PHP 应用,如 WordPress(一种使用 PHP 语言开发的博客平台)、Joomla(内容管理系统)与 Drupal(使用 PHP 语言编写的开源内容管理框架)
节约开发成本:使用该功能无需支持额外费用,因为资源共享的缘故,您只需支付“应用服务(App Service)”计划费用即可
MySQL 与 Web 进程能在相同环境下同时协作,进而实现存储共享
支持慢速查询日志与通用日志两种模式,您可在需要时选择打开相应模式即可(该功能会影响性能,请不要一直打开)