From this AWS lightsail WordPress database article, our WordPress Support Services will show how to transfer WordPress website data to a MySQL-managed database in Lightsail at Bobcares.
Connecting WordPress to MySQL database in AWS Lightsail
WordPress website data for posts, pages, and users, are stored on the MySQL database that runs on the instance in Amazon Lightsail. If your instance fails, the data will become unrecoverable. To prevent this, you should transfer website data to a MySQL-managed database.
We will show you how to transfer WordPress website data to a MySQL-managed database in Lightsail. Also, how to edit the WordPress configuration (wp-config.php
) file on the instance. So that website connects to the managed database and stops connecting to the database running on the instance.
Step 1: Complete the prerequisites
Complete the following prerequisites before getting started:
- Initially, create a WordPress instance in Lightsail, and make a note that it’s in a running state.
- Create a MySQL-managed database in Lightsail from the AWS Region as your WordPress instance. This should also in a running state.
- Next, you need to enable the public mode and data import mode of MySQL-managed database. You can disable Modes after completing the steps from this guide.
Step 2: Transfer the WordPress database to a MySQL-managed database
Complete the following procedure to transfer your WordPress website data to a MySQL-managed database in Lightsail.
1. Sign in to the Lightsail console.
2. In the Instances tab. Select the browser based SSH client option for the WordPress instance.
3. After the browser based SSH client is connected to the WordPress instance. We need to transfer the data in the bitnami_wordpress
database that is on the instance to your MySQL-managed database, from the below command. Here replace DbUserName with the user name of your managed database. Similarly, Replace DbEndpoint with the endpoint address of your managed database.
sudo mysqldump -u root --databases bitnami_wordpress --single-transaction --compress --order-by-primary -p$(cat /home/bitnami/bitnami_application_password) | sudo mysql -u DbUserName --host DbEndpoint --password
4. At the prompt SSH screen. Enter the password for your MySQL-managed database. Press Enter. As you type, the password will not show up.
5. If the data was successfully transferred and in case you get an error, confirm that you’re using the correct database username, password, or endpoint, and give a try again.
Step 3: Configure WordPress to connect to MySQL-managed database
Complete the procedure to edit the WordPress configuration file (wp-config.php
). So that the website connects to your MySQL-managed database.
In the browser-based SSH client connected to your WordPress instance, you need to create a backup of the wp-config.php
file in case something goes wrong.cp /opt/bitnami/wordpress/wp-config.php /opt/bitnami/wordpress/wp-config.php-backup
Enter the below command to open the wp-config.php
file using the Nano text editor.nano /opt/bitnami/wordpress/wp-config.php
Scroll down till you get values: DB_USER
, DB_PASSWORD
, and DB_HOST.
Modify the following values:
- DB_USER — Edit the user name of your MySQL-managed database to match.
- DB_PASSWORD — Edit with the strong password to match with MySQL-managed database.
- DB_HOST — Edit the endpoint of your MySQL-managed database. Add
:3306
port number at the end of the host address.
Save and exit the text editor.
Enter the following command to restart the web services on your instance.sudo /opt/bitnami/ctlscript.sh restart
You will get the result as syntax OK.
Congratulations! Your WordPress site is now successfully configured to use the MySQL-managed database.
Step 4: Complete the next steps
Once connecting your WordPress website to a MySQL managed database. You should complete these additional steps:
- Create a snapshot of the WordPress instance.
- Create a snapshot of the MySQL managed database.
- Disable the public mode and data import mode of MySQL managed database.
[Looking for a solution to another query? We are just a click away.]
Conclusion
To sum up, your WordPress website is now configured to use the MySQL managed database. Also, how to edit the WordPress configuration (wp-config.php
) file on the instance.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
0 Comments