CSV to MySQL Table [EasyPHP + PHPMyAdmin]

This article assumes you have installed and set up the EasyPHP Devserver in your Local Environment. Please click here to complete these steps before moving forward if you have not done so.

Ensure the following steps are completed before moving forward:

  • Start EasyPHP
  • Open the Dashboard
  • Start the HTTP and Database servers

As a precursor to this article, if you are unfamiliar with MySQL, click here to read the documentation.


Working with Modules

This section shows you how to import a CSV file into a database and table that has not been created.

Import a CSV file into a MySQL Database

To get started, click here to download the fictitious Finxter CSV file and save it to the Desktop.

If you have not done so, open the EasyPHP Dashboard and navigate to the MODULES area.

Click the open button for any of these MySQL modules to take you to the phpMyAdmin page.

πŸ’‘Note: All three (3) MySQL Administration links are identical (at this time) and take you to the same phpMyAdmin area.

From the phpMyAdmin screen, click the Import tab across the top bar to be forwarded to the Import screen.

From the Import screen, click the Choose File button to browse and select the previously downloaded CSV file.

After the CSV file has been uploaded, the bottom portion changes to reflect the selected file type. In this case, a CSV file.

In the Format-specific options area:

  • Columns separated with: The fields in the Finxter CSV file are separated with a comma (,). Therefore, no change is required here.
  • The first line of the file contains the table columns: Place a checkmark in the checkbox confirming the first row of the CSV file is a header row.

When ready, click the Go button to start the import process.

If successful, a screen similar to the one below displays.

Since no Database or Table was created before importing the records, the system assigned default names: csv_db (database) and tbl_name (table).

πŸ’‘Note: Click the csv_db link in the left-hand panel to expand, and the tbl_name link will become visible.

Click the tbl_name link to view the contents of the table.

As you will notice from the pagination at the bottom, there is more than one (1) page of imported records. Click these buttons to navigate through the records.


Rename the MySQL Database

To better reflect the data imported, let’s rename the database from csv_db to finxters_db.

Before moving forward, ensure you select the appropriate database by clicking the finxters_db link in the left-hand panel.

πŸ’‘Note: The Operations screen displays different content based on the selection. For example, a database, a table, etc.

Next, click the Operations tab located across the top bar to be forwarded to the Operations screen.

Enter a new database name in the Rename Database area. For this example, finxters_db was entered.

Remove the checkmark from the Adjust Privileges checkbox and click the Go button to confirm.

A pop-up appears, prompting you to confirm. Then, click the OK button to change the name.

πŸ’‘Note: This operation deletes the current database csv_db and creates the new database finxters_db. No worries! Your data is safe!


Rename the MySQL Table

Before moving forward, ensure you select the appropriate table by clicking the tbl_name link in the left-hand panel.

Then, click the Operations tab located across the top to be forwarded to the Operations screen.

Enter a new table name in the Table Options area. For this example, users_tbl was entered.

Remove the checkmark from the Adjust Privileges checkbox and click the Go button to confirm.

If successful, the renamed database and table will display on the left-hand side of the phpMyAdmin area.

πŸ’‘Note: These operations could also be done by running a MySQL query. However, this is beyond the scope of this article.


Summary

This article taught you how to import a CSV file into a MySQL database, view the imported records, and rename the database and the table.

The following article, Display a Web Page using EasyPHP, Python and PHP, focuses on creating a PHP script that calls in a Python script and view in a Browser!


Programmer Humor

It’s hard to train deep learning algorithms when most of the positive feedback they get is sarcastic. — from xkcd