MySQL for Beginners - How to Create a MySQL Database

Whether you are an experienced webage, than you would need five (5) fields. Simply
programmer or a complete novice attempting toenter the number 5 in the appropriate box. Once
provide data interactivity with your web site,you hit create, the system will create a table and
MyQSL is an easy to use and free databasewill add those fields into the table for you.
solution that can allow you to store and configureDon’t worry about the number of fields
data to be displayed on your web site.you might need right now, as you can always add
The best way to create and manage a MySQLor delete fields later.
database is to download an open source (free)Step Three: Defining Fields
program called PhpMyAdmin. PHPMyAdmin allowsOnce you have created your table you will be
you to manage all aspects of both your databaseprompted to tell the database what features that
structure and data from one easy to useyou want each field to have. This looks
interface. This tool is intended to handle thecomplicated, but it’s not if you select your
administration of MySQL over the Web.data type from the information below. You
This tool provides an interface that allows you tobasically have to decide between three common
create and drop databases, create, drop, or alterdata types and select the best choice for storing
tables, delete, edit, or add fields, execute anyyour data. If you make a mistake you can go
SQL statement, manage keys on fields, manageback and edit the field.
privileges, and import and export data into variousIf the field is to be used to store numbers, here
formats. That sounds like a complicated set ofare some choices:
activities, but the easy to use graphical toolsTINYINT – A very small integer. The signed
make things quite simple and easy to understand.range is -128 to 127.
If you make a mistake, the software evenSMALLINT - A small integer. The signed range is
provides instructions on where you made your-32768 to 32767.
error.MEDIUMINT - A medium-size integer. The signed
For a complete demo see: [range is -8388608 to 8388607.
For documentation visit:INT - A normal-size integer. The signed range is
Most Linux based web hosting companies provide-2147483648 to 2147483647.
PhpMyAdmin as a standard feature with theirBIGINT – A very large integer.
packages. It is also available in aSome other less common number options include:
“Windows” IIS version. If yourFLOAT- A floating-point number.
hosting provider does not already have thisDOUBLE – A double-precision floating-point
product installed they will often install it for you, ornumber.
even allow you to install it yourself. Setup is quickDECIMAL - A packed exact fixed-point number.
and easy if you follow the step-by-step installationIf the field is to be used to store text or both
documentation.text and numbers combined, here are some
Step One: Creating your new databasechoices:
When you log in to your PhpMyAdmin welcomeVARCHAR is for varying characters and can be
page, the first step is to enter a name for yourup to 255 characters in length.
new database in a text box provided. You canTEXT is a column with a maximum length of
name your database anything that you wish,65,535 characters – easy to search.
however if you are creating the database to useBLOB is a column with a maximum length of
with a script or software package that you65,535 characters – case-sensitive.
purchased somewhere, the script provider willIf the field is to be used to store dates, here are
often suggest a “preferred”some choices:
database name.DATE - A date.
You should always create your database using theDATETIME - date and time combination.
following format:username_ databasenameTIMESTAMP - useful for recording the date and
Example: myusername_mydatabasetime of an INSERT or UPDATE operation.
Your complete database name should alwaysTIME - A time.
begin with your username followed by anOnce you have selected the data type for your
underscore, then followed by the database name.fileds you will need to let the system know how
This allows the server to know which user is inmany characters that you will need to store in
control of the new database, and it will alsothe field.
provide permission to access the database toExample: if you are storing a username, you
only specific users. This also allows different usersmight want to select VARCHAR as your data
on the same server to use the same name fortype and allow up to 100 characters for that field.
their own database, as you did, without interferingIf you are creating a User Identification number
with your data – that is helpful if more thanyou might want to select INT and allow up to six
one user on your server bought similar softwarecharacters – that would allow you to have
for their own site. They can then also use theup to 999,999 users.
software providers “preferred”The last step to creating your data fields is to
database name.select any special attributes that you may find
Step Two: Creating a table for your newhelpful.
databaseSome examples are:
After you have created a database, the nextAuto Increment: Auto-Increment fields are useful
step is to create a table, or even multiple tables,for assigning unique identification numbers for
for you to store data. A table is the part of yourusers, products, and customers, etc. By default,
new database that actually stores data.fields are incremented using number characters
You create a table by selecting the database that(like "1", "2").
you created from the drop box list of databases.Primary Key: The primary key is a data column
Once a database is selected a new form appearsthat uniquely identifies a specific instance of that
and asks for you to create a new table.data. At least one of your fields must be a
You must decide what you want to name yourPrimary Key. Username is an example of a good
table and enter that name into the name box. Tryprimary key. You do not want to have more than
to choose a name that reflects the type of dataone individual having the same username.
that will be stored in the table, such as orders,Index Key: Allows you to speed up searches by
users, or inventory.designating a field as a preferred data source,
You then must decide how manyespecially when combining data from multiple
“fields” or columns of data that youtables.
want to store for each record. If you need forCongratulations, once you have completed these
the table to store five (5) different items, such assteps you are ready to import data into your
username, users email address, users telephonenew database.
number, users account number, and the users