Skip to content

Viewing a table in MySQL is a fundamental task for database management, ensuring you can quickly access and review your data. While viewing tables provides basic data access, understanding various viewing methods and their strengths empowers you to effectively visualize and analyze your data. Let’s delve deeper into different options, helping you choose the most appropriate approach to gain valuable insights from your tables.

How to view a table using the MySQL command line?

To view a table in MySQL through the command line, execute these steps:

  1. Log into your MySQL server with the command:

    mysql -u username -p
    

    Substitute username with your actual MySQL username.

  2. Choose the database that contains your table:

    USE database_name;
    
  3. Retrieve the entire contents of a table:

    SELECT * FROM table_name;
    

    Change table_name to the name of your specific table.

  4. To fetch specific columns, replace with the desired column names, separated by commas:

    SELECT column1, column2 FROM table_name;
    

How to view a table using PHP?

Integrate MySQL data with a PHP script to display table data dynamically:

<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_dbname";

// Establish connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Confirm connection success
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM table_name";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // Display each row's data
  while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
  }
} else {
  echo "0 results";
}
$conn->close();
?>

Ensure you replace your_username, your_password, your_dbname, and table_name with the correct details for your database and table.

How to view a table using phpMyAdmin?

Leverage phpMyAdmin for a user-friendly graphical approach to managing MySQL databases:

  1. Log into your phpMyAdmin dashboard.
  2. Select the relevant database from the left-hand menu.
  3. Click on the table you want to view; its contents will then be displayed.

By adopting a more active approach in viewing and managing your MySQL tables, you streamline your database management processes, leading to more efficient data handling and analysis.

Written by

Robert Cooper avatar

Robert Cooper

Senior Engineer at Basedash

Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.