Tag Archives: MySql

Database connection error using MySql in Azure App Service

Well, if you’ve gone full speed ahead using the preview of MySql in Azure App Service you’ve noticed that it doesn’t work. WordPress gives you the “Error connecting to database” error.

To fix it you’ll need to add some application settings on your application.

Value: –default_password_lifetime=0

Click “Save” and you’re all done.


Running WordPress in Azure Webapp with Mysql

In August Microsoft launced the preview of Mysql in-app for Azure webapps. This means that you can enable Mysql in your webapp and you’ll get immediate access to a Mysql database within your application. Running WordPress, Joomla or any other PHP/Mysql-based CMS have never been easier. Please note that this is at the moment not for production workloads due to the single-instance database. Read the article for more information at https://azure.microsoft.com/sv-se/blog/mysql-in-app-preview-app-service/.

So how do you get it up and running?

Create a new webapp.


Name your webapp and if you don’t have one, create an App Service Plan.


Once deployment is finished we need to edit some settings.

Switch to PHP 5.7, and turn off ARR. Click Save.


The magic of turning on MySql is up next. Click “on” and if you’re just testing, don’t touch the logging settings. Click “Save”.


Now you’ll need to head over to WordPress.org and download the package. Save it on your computer and unzip the files. You’ll also need an FTP client. Assuming you’re running Windows you can grab Filezilla for free.

Edit your deployment credentials if you don’t know then.


Check the portal for your FTP hostname and enter the corresponding values in your FTP client.


When the upload is done you can use the brand new editor to change wp-config-sample.php.



You need to delete some code and paste in the following code:

$connectstr_dbhost = '';
 $connectstr_dbname = '';
 $connectstr_dbusername = '';
 $connectstr_dbpassword = '';

foreach ($_SERVER as $key => $value) {
 if (strpos($key, "MYSQLCONNSTR_localdb") !== 0) {
 }$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);
Paste the code and save
Rename the file wp-config-sample.php to wp-config.php. This can be done in your FTP client.
Once done you can click your URL in the portal.
If you’ve done everything right so far you’ll see the WordPress installation guide.
Select your language.
Enter a username / password.
Once it’s done you can visit your site and you’re all done. Now you can apply a custom theme and fill your site with content.
Does it work? Well, this site runs in the exact same manner as the guide. So far, so good 🙂

Downgrading you ClearDB MySql database in Azure

Are you running a website or application in Windows Azure with data stored in MySql? I upgraded my database from the free database with a maximum of 20 Mb to the 1 GB option, costing me $9.90 a month. Well, I cleared it out and was going to do a downgrade from payed to free again. Well, it seems ClearDB doesn’t really like downgrading since the Revenue stream goes sour… So you’re on your own and need to create a new database and manually (woop!) migrate data. Feels like we’re back to 1886.

Login to ClearDB site
Create a new database in the free plan
Copy server name, user name and password to a textfile, or just remember it all 🙂
Download MySql Workbench from Oracle (http://dev.mysql.com/downloads/tools/workbench/)
Install Workbench (next, next, finish)
Get the server name, user name and password to your existing database, wp-config.php has it or check the connection strings for your Azure website.




Configure MySql Workbench to connect to old server
 Dump database










Edit dump file to reflect new server and database name. Or make corresponding changes in Workbench, but this is easier to explain.









Import/restore to new database in Workbench










Edit wp-config.php to reflect new server name









Verify it all works by reloading your website in your browser. (important!)

Delete old database on ClearDB site. This will also clear your payment plan. Login to Amazon and verify your payment authorizations to make sure.