SQL Database Tutorials and Advice: A Guide to Learning the Basics of Relational Databases

SQL Database Tutorials and Advice: A Guide to Learning the Basics of Relational Databases

Updated on February 7th, 2004 this tutorial is written with the intention of giving new users a quick start to relational databases. It will assume the reader has some programming experience; however, it still might be useful for those with limited programming knowledge–just perhaps not as much fun. The topics covered here are by no means complete (see the end of the article for a list of database books), but should give you a good introduction to relational databases. 

Relational database management systems (or just databases) are one of the most important technologies in use today. They are absolutely essential for large companies that need to organize and juggle massive amounts of data, but they also play an important role in small companies too. This tutorial will introduce you to the basics of the database management system MySQL. For this tutorial, it does not matter whether or not you are using Linux or not, though if you are using Windows I’d definitely recommend using MAMP (link below), which is a way for you to get up and running with MySQL quickly and easily. First, we’ll need to install MySQL (if you’re not using MAMP), and then we will create a simple database with some tables in it.

Creating Your Database 

To start off, let’s go ahead and download MySQL here. Once that is downloaded, unpack the installer into your *nix home directory or a directory of your choice. After you have unpacked it, go ahead and change it into the directory where MySQL is installed (e.g., cd ~/MySQL-5.0.45 or wherever); now we need to run a little script that will create a database for us along with some tables inside of it: sudo ./scripts/mysql_install_db You should see some text scroll by; this is MySQL creating our database and the tables inside of it. Now we need to make sure that we can log in to our newly created database: –

You should now be able to type this into your terminal: my SQL admin version If you get a result back, then you have successfully installed MySQL! Congrats! We will now create a simple “users” table in which we will store user information such as their name and email address. To do this, type this in: –

Now let’s now create the login table by typing this command (notice that I have added an entry for email; if your website is going to be storing sessions you need to make sure that each user gets a unique identifier, so you should either give them their username or include some sort of unique number). Now just type exit into the terminal to exit SQL mode and then quit to close MySQL. Then launch the phpMyAdmin program from your main menu–this will open up a web interface, which will allow us to enter data into our database using a web interface! You can log in as the root user with no password. Before we go any further though, it is advisable that you change the root user’s password and create an additional user. If you did not follow the previous step, go back and do so! 

Now we need to change the permissions on our new table: –

Now we can start using phpMyAdmin, but before we do so we need to tell it where our database is located (go ahead and log in as root if you haven’t already–no password required). We’ll also want to create a new table by clicking on that tab. Right now this table will just be for test purposes; let’s name it users. Okay, now press Create. Once you’ve created your new table successfully, click on Structure at the top of the page. Near the bottom, there be an entry for lines; double click on it. 

We need to make two changes here: –

  • Now click the Save button at the bottom, then close the window. Now let’s fill our table with some data! You can do this by simply typing into your terminal MySQL -u root -p < data base_name Here I will be inserting some values for user jake: –
  • If you want to add more records, just keep doing that. Now if you go back into php My Admin and click on the SQL tab at the top of the page, then type this in: SELECT * from users This should give a result for every single entry in your table! All done! That’s basically it for this tutorial, but before I end it let’s add a new user by using the insert command (notice that we are inserting one row, but we can put in as many rows as we want).

Conclusion: 

MySQL is a powerful way of storing data, and using php My Admin for managing your databases makes it even easier. I hope that this tutorial has allowed you to get started quickly and easily with MySQL! If you have any questions or comments, feel free to leave them below or contact me directly.

Leave a Reply

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

Back To Top