You are on page 1of 8

CSS 326 Database Management Laboratory: PHPMyAdmin & MySQL

School of Information and Computer Technology


Sirindhorn International Institute of Technology
Thammasat University
CSS 326 Database Management Laboratory

Laboratory #4: PHPMyAdmin & MySQL

Objective: - To learn how to use phpMyAdmin


- To learn how to connect to MySQL

1 phpMyAdmin
phpMyAdmin is one of the most popular freely available tool, written in PHP, to manage
MySQL and MariaDB databases over the web. It is also one of the most commonly used
database management tool provided by Web hosting solution providers to provide user an
interface to manage the allocated database.
Many people have difficulty understanding the concept of user management with regards to
phpMyAdmin. When a user logs in to phpMyAdmin, that username and password are passed
directly to MySQL. phpMyAdmin does no account management on its own (other than allowing
one to manipulate the MySQL user account information); all users must be valid MySQL users.
1.1 Accessing phpMyAdmin

Start your servers. This can be done from the XAMPP/MAMP application that you installed.
On some systems there may also be an application icon that can be used (Red box: Admin).

Also, you can access to phpMyAdmin with a URL just like usual web pages. By default, the
URL is
http://localhost/phpmyadmin/

© Copyright ICT Program, Sirindhorn International Institute of Technology, Thammasat University

Last Updated: 2/9/2022


CSS 326 Database Management Laboratory: PHPMyAdmin & MySQL

Once you log in, a phpMyAdmin screen appears as shown next.

1.2 Creating Database

You can create new databases and import tables using phpMyAdmin. Create a database by
clicking on the “New” link at the top of the left panel, or navigate to the Databases tab.
Enter a name for your new database (e.g., “New”) and select a “collation”, which is the
encoding format used to store text characters. The collation can be important for storing
characters like vowels with umlauts or accents. When in doubt, chose “utf8_unicode_ci”,
which will handle most characters from European alphabets.

Click “Create” to create the database.

© Copyright ICT Program, Sirindhorn International Institute of Technology, Thammasat University

Last Updated: 2/9/2022


CSS 326 Database Management Laboratory: PHPMyAdmin & MySQL

1.3 Creating Table

Click on any listed database to see the list of tables with more details. On the new page that
opens you will see a list of all the current tables inside the database and a section named Create
table. In that section, in the Name field, input the desired new name of the table and then select
the number of columns that the table should have via the Number of columns drop-down. When
ready, click on Go to create the table.

On the next page, you can configure the structure of the columns in the new table. The different
fields there are:

• Name – The name of the column;


• Type – The type of data, which will be stored in the corresponding column. More details
about the possible choices can be found in the official MySQL Data Types documentation;
• Length/Values – The length of the field;
• Default – With this option, you can specify if the fields in the column would have a default
value. This is useful when you want to have timestamps for the entries in each row;
• Collation – The data collation for each of the fields;
• Attributes – assign any special attributes to the fields;
• Null – Define whether the field value can be NULL. More about the NULL value can be
© Copyright ICT Program, Sirindhorn International Institute of Technology, Thammasat University

Last Updated: 2/9/2022


CSS 326 Database Management Laboratory: PHPMyAdmin & MySQL

found in the MySQL documentation;


• Index – Set the Index of the row. More information about the MySQL column indexes can
be found in the MySQL documentation;
• A_I – Short for Auto Increment. If this option is enabled then the values in the fields of
the column will be auto incremented;
• Comments – Here add comments, which will be included in the database SQL code.

After you configured the different columns, specify the Collation and Engine of the new table via
their respective drop-downs.

When ready, click on Save to create the new table.

Congratulations! You have created your first table in phpMyAdmin. The corresponding SQL
command for creating these fields is also displayed. Note that you can use Drop to delete a
table or fields.

1.4 Inserting New Records

To add records inside a database table, open the table with phpMyAdmin and click on the Insert
tab.

Enter the desired data in the corresponding fields and click on Go to store it. You can see the
newly inserted record by clicking on the Browse tab. You can click on individual records for
editing or deleting.

1.5 Browse

Only the tables with existing records can be browsed. After you click on the Browse icon a
new tab with the records list will be opened.

© Copyright ICT Program, Sirindhorn International Institute of Technology, Thammasat University

Last Updated: 2/9/2022


CSS 326 Database Management Laboratory: PHPMyAdmin & MySQL

By clicking on the Pen icon you can edit the chosen record. You will see the record structure
and you can alter the values of the records.

1.6 Structure

In the Structure screen you will see the table structure.

You will see the fields' names, their types, collations, attributes, additional extra information,
the default values and whether the fields' values can be NULL. You can browse for distinct
values by clicking on the corresponding action icon. Also, you can edit a field's structure or
delete a field. You can define different indexes: Primary, Unique, Index and Fulltext. This
structure information is equivalent to the result after issuing “desc” command in the MySQL
command-line client.

© Copyright ICT Program, Sirindhorn International Institute of Technology, Thammasat University

Last Updated: 2/9/2022


CSS 326 Database Management Laboratory: PHPMyAdmin & MySQL

1.7 Search

Through the Search menu, you can generate a search query for the chosen table.

You can either write the WHERE clause or you can use the "query by example" functionality.
You should click on the Go button to execute the query.

For example, if you want to visualize all the records with a field value that starts with a, you
should select the fields which you want to show. Pick the LIKE operator from the drop-down
menu and enter in the corresponding field value a% (% stands for a wildcard string). Click on
the Go button to see the result.

1.8 SQL

You can run a MySQL query through “SQL” Tab. There you should enter the entire SQL query
code and click on the Go button to execute it. You can press Ctrl+Space to open the relevant
suggestion as well.

© Copyright ICT Program, Sirindhorn International Institute of Technology, Thammasat University

Last Updated: 2/9/2022


CSS 326 Database Management Laboratory: PHPMyAdmin & MySQL

You can find more details about the MySQL syntax in the official MySQL Documentation.

1.9 Backup the Database

You can create a backup of your database through the “Export” tab.

Select the tables you want to exported. Leave the radio button selection to the SQL
option. The Structure and the Data check boxes should remain checked.Select the Save as
file check box and then click on the Go button. An SQL dump file with your database
structure and content will be generated.

If you have a large database with a lot of records, the server timeout value can be reached.
In such a case you can export the database in several batches.

1.10 Restoring the Database

You can restore your database backup in the “Import” tab. Under the File to import section,
click Browse and locate the file with the .sql extension you wish to import. Check or uncheck
the boxes for 'Partial import' and 'Other options'. From the Format drop down menu choose
'SQL'. Click the Go button at the bottom to import the database.

If you imported a database, all tables would show when selecting the database in the left panel
of phpMyAdmin.

If you imported a table, the newly imported table will appear in the list of tables.

© Copyright ICT Program, Sirindhorn International Institute of Technology, Thammasat University

Last Updated: 2/9/2022


CSS 326 Database Management Laboratory: PHPMyAdmin & MySQL

If the file is too big, the MySQL server timeout can be reached. In such a case you can
interrupt the import action. Then you can continue with the data import defining the number
of the queries to be skipped from the file beginning. In this way you will skip the imported
queries and continue from the point of the interruption.

© Copyright ICT Program, Sirindhorn International Institute of Technology, Thammasat University

Last Updated: 2/9/2022

You might also like