|
As we ramp up to begin using Amazon Web Services as our host, we find ourselves having to re-install and re-configure alot of software. One of the most important pieces of any web application is your database server, so today's tutorial will be a quick walkthrough of how to install MySQL on Ubuntu.
Step 1 - Install MySQL
Installing MySQL is relatively simple using apt-get. During the installation, you will be prompted to enter a password for the root login. Note that MySQL will automatically configure itself to boot on startup, which is probably a good thing.
apt-get install mysql-server
Step 2 - Create Your Schema
There are a couple ways to create a new schema, sometimes also known as a database. Our recommendation would be to first login to MySQL as follows:
mysql -p
You will be prompted to enter your password, after which you will be brought to a MySQL prompt. From there, create your new schema as follows:
create schema sample; use sample;
You can then create tables, stored procedures, etc. using standard SQL. For example, to create a new table you could use the following commands:
create table tbl (col1 int, col2 varchar(30));
Step 3 - Create Your User
If you are still logged into the MySQL prompt, you can create a new user that has access to the sample schema. It is generally good practice to create a user for each schema on your server, or in general dividing access among several user accounts. This ensures that if somebody hijacks an account (for example, through a SQL injection attack to one of your web sites), you limit the damage they can do and ensure they cannot access a different schema. For each user, you should only grant the permissions necessary for their role, but in our case we will grant full access to the sample schema for the sake of example:
create user 'me'@'localhost' identified by 'pass1234'; grant all on sample.* to 'me'@'localhost';
You can then login as this user to access the sample schema. First, leave the MySQL prompt by typing exit. Next, re-enter MySQL with the following command:
mysql -D sample -u me -p
You will be prompted for your password, after which you can use the sample database (create tables, add data, and run queries using SQL).
Conclusion That's really all there is to it. From here, you would most likely want to install your web or application server and get it linked up to your brand new MySQL database. Best of luck!
|