Search

FAQ > MySQL

Use the same values for the database connection locally and remotely

If you use a connection to the MySQL database in PHP applications, the values used for the database connection on the local system with MAMP PRO and the remote server are not identical in most cases. As a result, you have to provide different sets of connection data for each of the different execution locations (local, remote). But this does not have to be the case. With the capabilities provided by MAMP PRO, this extra effort is not necessary.

The plan is therefore to use the same database connection values for the local server environment and the remote server at the provider. We have to keep in mind that certain values are predefined by the provider and cannot be easily adjusted. For this reason, we will proceed in the following in such a way that we start from the data provided by the provider and use this as a basis for the values on the local side.

Provider database connection data:

  • Hostname: db52339873412.hosting-data.io
  • Database name: dbs8723017
  • Username: dbu4919316
  • Password: 3dft6hfdgjz9hd3skw

Let’s first create a new MySQL database using MAMP PRO with the name, username and password just mentioned. To do this, we proceed as follows:

  1. Open MAMP PRO.
  2. Start the servers.
  3. In the Hosts list of MAMP PRO, select the host with which you want to use the database.
  4. Now switch to the “Databases” tab.
  5. Click on the plus button at the bottom of the list of databases. The “Create database” dialog will open.
  6. Enter the database name in the “Name” field. In our example this is the value “dbs8723017”.
  7. Below the input field for the name there is a pop-up element “After creating the new database”. If this is still closed, click on the text to open it.
  8. Activate the checkbox in front of the text “grant access to User” and enter the user name in the input field behind it. In our example this is the value “dbu4919316”.
  9. Enter the password in the input field labeled “with Password”. In our example this is the value “3dft6hfdgjz9hd3skw”.
  10. Now click on the button labeled “Create”. The newly created database will appear in the list of databases. The activated checkbox in front of the name indicates that this database is linked to the selected host.

By default, MAMP PRO provides the host “localhost” for a connection to the integrated MySQL database. As you can easily see, this is very different from the host name given to us by our provider (see above). In order to be able to use this name locally, we have to make sure that the MAMP PRO servers know this name and forward requests to it correctly. For this we proceed as follows:

  1. Now switch to the “General” tab.
  2. In the lower part of this view you will find the “Aliases” section. Click on the plus button at the bottom.
  3. In the newly created entry, enter the host name for the database specified by the provider. In our example this is the value “db52339873412.hosting-data.io”.
  4. Now click on the button labeled “Save” at the bottom of MAMP PRO. This will save the changes and restart the servers.

Done! You can now use the same database credentials on your local server environment and on your provider’s server.