Thread: Article Competition - 3 Prizes!
View Single Post
  #4  
02-02-2006, 02:42 PM
Cypher_489
Member
 
Join Date: Nov 2005
Location: England
Posts: 89
Setup MySQL and phpMyAdmin

MySQL is the most popular type of SQL database and is widely used across CMS' and Bulletin Boards, such as PHP-Nuke and phpBB. phpMyAdmin is a graphical interface for MySQL databases for users with little or no knowledge of SQL code (It also offers the ability to input your own SQL code if phpMyAdmin is the only way you can access your database). This guide will help you setup MySQL and phpMyAdmin which should already be installed by your host.

PLEASE NOTE: This guide will be using cPanel as the host interface. The process should be the same for all hosts, although it may be slightly different.

::Setting Up MySQL::

1. Login to cPanel with your username and password. cPanel should be accessed from www.yoursite.com/cpanel.
2. Click "MySQL Databases". From here, you can add, edit and delete databases.



3. MySQL Maintenance (Fig 1).



4. Now, we need to create a Database, or DB (Fig 1.1). Type in a name for your database and click "Add Db". The database name will usually be preceded with your Hosting username to prevent conflicts of names between other users of the server. You have now created a MySQL Database!
5. Now we'll assign users for databases (Fig 1.2). If you are the only user, you do not need to do this as there will already a default username and password with global access (It should be the same as your hosting username and password). Enter a username and password, then click "Add User". This user can now access databases that you choose with varying permissions.
6. To assign a user to a database and set their permissions (Fig 1.3), select their username and the database you wish to assign to them, then you will need to set permissions. Choose what sort of access you will like to give that user. If you want to give them full access, choose "All". Otherwise, check the boxes that apply to that user and then click "Add User". Now you have a database with an additional user with variable access.
7. You can edit, check and repair existing databases (Fig 1.4) if you need to. However, if you believe that you have setup your database to your satisfaction, you can continue onto phpMyAdmin (Fig 1.5) where you can add tables, columns, rows and fields to your database.

::Using phpMyAdmin::

Depending on your version, things may be different for you. We will be using Version 2.6.4

PLEASE NOTE: This is in no way a comprehensive guide for phpMyAdmin. It is a guide to get a simple database setup.

1. On the left hand side nav bar, select your database from the drop down menu.
2. You now have a choice of whether to import tables from an SQL file or to create them manually. If you are using a pre-made script (such as PHP-Nuke), you will find that it already comes with an SQL file. To import the tables, continue to step 3. Otherwise, continue to step 4 to create the tables yourself.
3. To import tables from a file, click SQL at the top of the page. Then find "Or Location of the text file:", browse for the SQL file and click Go.



4. To create your own tables, click "Structure" at the top of the page. Find "Create new table on database Your Database Name:" type in the name of the table and how many fields you will be using. Then click Go.
5. You will now be presented with a screen to input however many fields you selected. In this example below, we will be using a Newsletters Member Table. Each of the fields will be explained in further steps.
6. Half finished example of a Newsletter's Member table.



7. In the field column, you will type the name of the field. In our example, we have used mid (Member ID). In the next column, you will specify the type of field you will be using. We have used "INT" in our example as the value for mid will be a number (INT stands for integer/number). The length column specifies the maximum number of characters for the field. You can generally ignore Attributes and Null as they are not widely used. The next column across is "Default" which specifies the default value for that field. This is useful if you have an on/off state for a field (e.g. Content Page - 0=inactive, 1=active default=0). In the "Extra" column, you can specify if an integer field automatically increments as a new row is added (e.g. 1st row - mid=1, the 2nd row will automatically be mid=2). In the following radio buttons, you can specify the primary key. This is generally the first field.
8. Now that you have inputted data for a basic table, you can add comments in the comments box or add additional fields. When you are happy with your table, click Save.
9. Congratulations, you have now setup a MySQL Database! Options for your database can be found in the Operations tab in the header and additional help can be found in the phpMyAdmin documentation which can be found here

Now that you have created a database, you will need to configure the script that will be using the database to match your host and database details. Generally, host will be localhost, username will be either your hosting username or the username you setup earlier (if you did), password will be your hosting password or the password of the user you setup earlier and database name will be the name you gave to your database (Your database name may be preceded with your username and an underscore if using a shared server.).

Callum Isitt/Cypher_489
__________________
Cypher_489

Free, Helpful PC Guides & Tutorials