| CREATE A MYSQL DATABASE |
In this section I will show you how to create an empty MySQL Database, for those occasions whereby a PHP Script for example needs one in order to function
properly. PHP Scripts normally initialize (fill in) the MySQL Database entries for you, hence why I am only showing you how to create an empty MySQL
Database. This example is also useful if you want to set up an empty MySQL Database for general data purposes such as for Membership details (name,
email address and so on). If you want to know how to create fields (data/title entries) for an empty mysql database you should read the section called
How To Create MySQL Database Entries.
A MySQL Database is just like a database you might create in Microsoft Office Access or Excel. It is written in a scripting language called SQL
(Structured Query Language), meaning you can create a mysql database by typing its mysql instructions into a text editor (i.e. Notepad) only or you can
use the software inside your CPanel control panel. A database is made up of a table of cells (squares/boxes like in MS Excel or other spreadsheet
applications) which contain Title cells (i.e. Name and Email Address) and Data cells (i.e. Mr John Smith and johnsmith@whatever.com). In each set of data
cells you insert a new customer's details for example. And it is the same with a mysql database. A Blog mysql database might be filled with many tables
(table of cells). One for blog users, one for blog comments, one for blog posts and so on. In this scenario the mysql database keeps a track of what is
going on in that blog. You could have many tables in a private mysql database (Table1: Members. Table2: Products) - The Title cells could be Product
Name, Bought, Sold, Price and Discount with the first Data cells (row) containing Shoes, 10, 5, £10, None and the second Data cells (row) containing
Slippers, 25, 19, £5.99, 10%.
The first thing you need to do is login to your web space (website) Control Panel
and then find and click on the MySQL Databases link. This will open the MySQL Account Maintenance control panel (Fig 1.1) that is split into two
sections - Databases and Users.
When the MySQL Account Maintenance control panel (window) appears it will display any previously created Accounts (MySQL Databases, User Names and
Passwords). For example. It is normal for a web host to have set up a service, on your behalf w/out your permission, that required a MySQL Account.
It is also normal for a website designer to have set up a MySQL Database for you, for whatever reason(s). Regardless of this though, in this example
I am showing you from scratch. Therefore, there are no MySQL Accounts/Databases set up yet.
A MySQL Account is created as follows. First you need to create an empty MySQL Database, to store the actual data in, by filling out the NEW DATABASE
Edit Box with the name of your MySQL Database. In this example I am creating an empty MySQL Database for a blog, so I will name it blog. When you
have typed in your desired database name click on the CREATE DATABASE button to continue.
After clicking on the CREATE DATABASE button (Fig 1.1 above) your are shown a confirmation window to confirm that the empty MySQL Database has been
created (Fig 1.2 above). Simply click on its GO BACK button to go back to the MySQL Account Maintenance control panel.
The next part to creating a MySQL Account is to create a User Name & Password. The user name and password, once created, can be assigned to any one
of your MySQL Databases. For example. If you have four MySQL Databases (i.e. blog, forum, customers and products) you can create a separate user name
& password for each MySQL Database or you can have just one user name & password for all four MySQL Databases. So you could assign user name john
to all four MySQL Databases or just assign john to the blog and forum MySQL Databases.....and then assign two other user names to customers and products
for example.
In this example I am creating the User Name john with the Password myblog2009 because it will be assigned to the MySQL Database called
blog. Creating the user name and password uses the same procedure as used for creating the MySQL Database. Simply type a user name into the
USERNAME Edit Box and a password into the PASSWORD Edit Box before clicking on the CREATE USER button.
In Fig 1.3 above you may of noticed the MySQL Database called blog is now called website1_blog. This is because each MySQL Database, once created,
is normally prefixed with your Web Hosting Account user name (in my case: website1) followed by an underscore (thus: website1_). The same applies to the
MySQL Database User - It will be given the (website1_) prefix as well (Fig 1.5 below).
At this point an empty MySQL Database and User (User Name & Password) have been created, but they are not connected/assigned to each other yet. To do
this, and to complete the MySQL Account procedure, you first have to select a User from the USER drop-down (Fig 1.5 below), if you need to select another
user and if there is more than one user of course. In this example website1_john is selected by default (normal behaviour) because it was the last user
to be created and also because it is the only user.
Once the User has been selected you then have to select a MySQL Database from the DATABASE drop-down menu, if you need to select another MySQL Database
and if there is more than one MySQL Database of course. In this example website1_blog is selected by default (normal behaviour) because it was the last
MySQL Database to be created and also because it is the only MySQL Database. When you have chosen a user and database click on the ADD button to continue.
After assigning a user to a database the next window to appear asks you to set the Privileges for that user. Privileges such as: Can the user DELETE a
record (data) in the MySQL Database? Can the user INSERT a record (data) into the MySQL Database? And so on. Put a tick next to each privilege you want
to allow/grant the user. In this example, and always, I leave the default (normal/standard) setting of ALL ticked to allow/grant all privileges to the
user. You should do the same in normal scenarios.
When you are happy with the privileges you have selected (ticked) click on the MAKE CHANGES button in order to set/assign those privileges for the user,
therefore creating the MySQL Account. In this example, User website1_john (with Password myblog2009) will be connected/assigned to the website1_blog
MySQL Database with ALL privileges enabled (allowed/granted).
Now that a MySQL Account has been created, with one MySQL Database and one User Name & Password, its details can be used by a PHP Script for example.
PHP Scripts normally ask you to edit a config.php file that must contain the name of a MySQL Database and a User Name & Password. If a PHP Script
needs to know what your Access Host is it is listed in the phpMyAdmin control panel and is normally localhost. Access Host is how the PHP Script
connects (has access) to your website.
If you need to delete a MySQL Database and/or a User simply click on the DELETE button next to each one. Deleting a MySQL Database on its own will
disconnect/unassign its user(s) whereas deleting a User on its own means the MySQL Database will be minus one user - If all users are deleted the
MySQL Database will be without a user of course.
After creating the MySQL Account and clicking on the GO BACK or HOME button (depending on your cpanel version) you can then use the phpMyAdmin control
panel to edit your database - create/delete Tables (Table of cells), fill in relevant Data entries (records) and so on.
The above is my website1_blog database with a set of wordpress blog Tables inside it, denoted by the wp_ prefixes. Clicking on one of those tables (table
links) will allows me to see the structure (data entries/records) for that table.
If you only have 1 MySQL Database with your web hosting package you can install a blog and forum for example using the same database. You do not need two
databases because each installation (blog installation and forum installation) normally uses it own prefix (i.e. wp_, yabb_, phpbb_ etc). Ideally though.
You want to give each installation its own database, especially in cases whereby you want to delete a database but cannot because it is storing another
installation's tables for example.
Remember. MySQL can be complex, even to someone with programming experience, so be sure you know what you are doing before clicking on the phpMyAdin link.
Otherwise you may trash an important MySQL Database or have a blog without a database for example that then may leave a control panel tool useless,
broken and/or redundant.
All HTM, CSS, PHP and MySQL files in the websitecreationhelp.com folder and its sub-folders are (c) John White, 2009. All Rights Reserved. Email: John