본문 바로가기
[AWS]/Highly Available, Scalable, AWS Stack

8. Install MySQL server on EC2 instance

by SAMSUNG CLOUD-OKY 2022. 1. 18.
반응형

 

# Run following commands after you SSH into your server

# install mysql-server package, you will need to enter a password, twice. Remember this password
sudo apt-get install mysql-server

# test mysql server installation
mysql -u root -p
<Enter password when prompted>

# exit mysql
mysql> exit

# edit localdb.php page with mysql server user and password, user should be root and password will be what you setup in the installation step above
sudo vi /var/www/html/localdb.php

// Setup local db connection details here
$con=mysqli_connect('localhost','DB_USERNAME','DB_PASSWORD');

 

 

In this video take a look at setting up a MySQL server on the EC2 instance right.

So this will be my SQL.

server and we have to install this on the EC2 instance and then we want to test the connectivity

from our PHP application to the mysql server and for that we first configure the MySQL servers details

such as username and password in this PHP page local db dot PHP And then we will test this using

the browser.

OK.

So let's see how to do this.

So here's my EC2 instance.

Right.

And first we will install my sql server using apt get

and the package name is mysql-server right.

And here we have to enter the root users password twice.

The second line is a confirmation.

Right.

And then the installation completes and then it's a good idea to test my SQL.

Right it's a good idea to test my sql as soon as you install it and then we will configure the mysql.

server details in our application.

So.

So the way to test is to say something like this mysql -u root and then minus p and then

supply the password that you just created during installation of the server.

So.

So heres how you connect to my sql and you can look at the databases here.

You can run some mysql commands like create database.

My db lets say OK and then you can exit.

This will bring you out of my sql and back to your EC2 instance.

Now lets configure our local db page and this is we will edit the page directly in the Apache document root.

Right.

So this is our local db dot PHP page and we can essentially go into this line right.

This is the connection details line.

And let's create our let's set up our username and password so we'll use root.

This is the mysql servers root user

And then the password which is what you have set up during the installation.

So this is the user and the password and then we save this file.

Right.

And then we can exit our SSH session.

Next we can verify we can test whether the application the local db dot PHP page is connecting successfully

to the to the mysql server or not.

Right.

And you can see it says connected successfully.

If you have not set this up correctly the installation did not go through properly if you did not supply the correct

password.

For instance then this will say failed to connect and you have to go and troubleshoot.

OK so in this video we have basically installed my sql server on an EC2 instance and then

we have configured the password and the user name in the application and we have verified the page as well.

So good luck with this task.

 

 

 

 

반응형

댓글