Azure: Where is default user/pass for Wordpress database using MySQL in-app(preview)? Azure: Where is default user/pass for Wordpress database using MySQL in-app(preview)? wordpress wordpress

Azure: Where is default user/pass for Wordpress database using MySQL in-app(preview)?


The connection string can be seen in D:\home\data\mysql\MYSQLCONNSTR_localdb.txt. You can locate this file through Kudu Debug Console which could be accessed via https://<yourwebsitename>.scm.azurewebsites.net/DebugConsole.

The file content looks something like:

Database=localdb;Data Source=127.0.0.1:54306;User Id=azure;Password=6#vWHD_$

Following is a sample code snippet using PDO to connect MySQL in-app.

$dsn = 'mysql:dbname=localdb;host=127.0.0.1:54306;charset=utf8';$user = 'azure';$password = '6#vWHD_$';try {    $dbh = new PDO($dsn, $user, $password);} catch (PDOException $e) {    echo 'Connection failed: ' . $e->getMessage();    exit;}echo "Success: A proper connection to MySQL was made!";

Important update:

From https://social.msdn.microsoft.com/Forums/azure/en-US/4c582216-bc1b-48b0-b80b-87ae540c3d05/php-azure-mysql-inapp-changed-ports-randomly

A VM can host multiple WebApps; hence multiple in-app MySQL processes. When we start MySql process, we attempt to use the same port as before. However, it may be taken by other service or other in-app MySQL. As a result, the port may change. In addition, web app can be moved from one VM to another and the set of available ports will be different.

In order to write the stable client app, do make sure you read the connection info from env variable. See this for more details.

So we should get the connection string from env variable in PHP like below:

$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);}


go to Configuration then add connection

Name = defaultConnectionValue = Database=your_database;Data Source=your_website.mysql.database.azure.com;User Id=your_username;Password=your_password

then for me suresh42326 answered worked

For me, visiting .azurewebsites.net solved my issue. after that I browsed .scm.azurewebsites.net/phpmyadmin, it didn't ask password.

https://github.com/projectkudu/kudu/issues/2238#issuecomment-427358981


/*Add at the begining of the fileif you want to connect to custom database then fill this variable  $connectstr_dbname = 'MY_CUSTOM_DB'; and comment or remove  $connectstr_dbname = preg_replace("/^.*Database=(.+?);.*$/", "\\1", $value); from below code...*/$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);}// ** 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);