DigitalOcean Managed Databases

Connect Laravel to a managed MySQL on DigitalOcean2 min read

Last year DigitalOcean introduced their take on DBaaS, which is a managed database service (DataBase as a Service – DBaaS), and this year they started support for MySQL as well. For all Laravel developers this is great as some of the overhead now can be outsourced without being costly, starting at just $15 per month.

But what is it DigitalOcean offers? From their website it says:

Leave the complexity of database administration to us. We’ll handle setting up, backing up, and updating — so you can focus on building great apps.


Create database

To create your managed database log into DigitealOcean and create a MySQL database

Fill in information as below or modify to your needs, you can always scale it later if it’s too small, you can even change location later as long as there are free slots available. You should pick a unique name for your database of course.

DigitalOcean Create Database

Create user

To create a Laravel user, navigate to Users & Databases for your new database and fill the Add new user with your desired username, you should also create a database in the table below.

Unfortunately at this time being DigitalOcean doesn’t allow for creating a user with access to only one database – at least not through their interface.

Laravel fix

The database is installed and ready to run – almost. Before you can access it from Laravel you have to change how users are authenticated. This is unfortunately not a simple switch in the control panel of DigitalOcean, but I have previously requested this to their support, so hopefully in the future it will be easier.

Instead you must log into your database and for every user that will be accessed from Laravel change to mysql_native_password.

Applying fix

Navigate to Overview for your database in DigitalOceans dashboard and take a note of Connection parameters to the right. This is the information you need to connect to your database.

Here is how it looks in HeidiSQL

Connect DigitalOcean Database

Go to the Query tab and execute the following. Remember to change myuser and mypassword.

ALTER USER myuser IDENTIFIED WITH mysql_native_password BY 'mypassword';

If you are using MacOS you should be able to use Sequel Pro to login and execute the command

If you are using Windows you can use HeidiSQL to execute the command.

Note from DigitalOcean

As mentionend I already requested a confirm from DigitalOcean whether this was the way to do it:

Happy to assist here!
That is exactly correct, you can do it manually with a command similar to:
ALTER USER myuser IDENTIFIED WITH mysql_native_password BY ‘mypassword’;
With the user and password inserted in.

DigitalOcean support on email

Leave a Reply

Your email address will not be published. Required fields are marked *