What Is MySQL? An Introduction to Relational Databases and SQL

Learn what MySQL is, how relational databases and SQL work, common web application uses, and how MySQL compares with other RDBMS products.

MySQL is a relational database management system (RDBMS). It is software used to create, store, organize, retrieve, update, and protect structured data. Websites and applications use MySQL to manage information such as user accounts, products, articles, orders, comments, and settings.

This lesson introduces databases, the relational model, SQL, MySQL's role in a web application, and the tools used to administer it. No previous SQL or programming experience is required.

What Is a Database?

A database is an organized collection of data. For example, an online store might keep customer names, product details, prices, stock quantities, and orders in a database.

A database management system (DBMS) is software that creates and manages databases. MySQL is a DBMS, and more specifically an RDBMS because it organizes data using related tables.

It is useful to distinguish the MySQL product from an individual database. The MySQL server is the database software that runs and manages data. A database is a particular organized collection hosted by that server. One MySQL server can host multiple databases, and each database can contain multiple tables.

What Does a DBMS Do?

Applications could store information in ordinary files, but a DBMS provides specialized systems for reliable, organized data management. Common DBMS responsibilities include:

  • Persistent storage: keeping data after an application or computer restarts.
  • Querying: finding specific information efficiently.
  • Updates: inserting new records and changing or deleting existing records.
  • Data organization: arranging information into tables, columns, indexes, and relationships.
  • Access control: deciding which users and applications may read or change data.
  • Concurrent access: allowing many users or application requests to work with data while helping prevent conflicting changes.
  • Backup and recovery: supporting copies of data and restoration after mistakes or failures.

Using a DBMS is usually safer and more practical than placing important structured information only in files. A DBMS can enforce rules, search large collections of data, handle simultaneous requests, and provide controlled access.

The Relational Database Model

The relational model organizes data into tables and connects those tables through relationships. Each table normally represents one type of thing, such as users, products, or orders.

  • A table is a structured collection of related data arranged in rows and columns.
  • A row is one record or item in a table. A row in a users table might represent one person.
  • A column is a named attribute shared by the rows. Examples include name, email, and created_at.
  • A field commonly means one data value associated with a column in a particular row.
  • A key is a column or group of columns used to identify rows or connect tables.

Primary Keys

A primary key is a column, or set of columns, that uniquely identifies each row in a table. For example, every user could have a different numeric user_id. Two rows should not have the same primary-key value.

Foreign Keys and Relationships

A foreign key is a value that references a row in another table. It creates a relationship between the tables. For example, a post can contain an user_id value that points to the author in the users table.

Related information is commonly separated into multiple tables instead of being repeated in one large table. This can reduce duplication and make changes safer. If an author's email address changes, the application can update the users table rather than changing a copy in every post. SQL can then combine or filter related data when needed.

TermMeaningSimple example
DatabaseAn organized collection of data.A shop's product and order data.
DBMSSoftware that manages databases.MySQL.
RDBMSA DBMS based on tables and relationships.MySQL, Oracle Database, or Microsoft SQL Server.
TableA collection of related data in rows and columns.customers.
RowOne record in a table.One customer.
ColumnA named attribute or field.email.
Primary keyA value that uniquely identifies a row.customer_id.
Foreign keyA value that references another table's row.posts.user_id.
SQLThe language used to work with relational data.SELECT.

Example: A Blog's Tables

A blog can store author information separately from article information:

TableKey columnsPurposeRelationship
usersuser_id, name, emailStores author accounts.user_id is the primary key.
postspost_id, user_id, title, body, published_atStores articles.post_id is the primary key; user_id references users.user_id.

A single author can be associated with many posts. The author details do not need to be repeated in every post row.

What Is SQL?

SQL means Structured Query Language. It is a language used to work with relational data. SQL can define database structures, retrieve data, insert records, update records, and delete records.

MySQL uses SQL, but MySQL and SQL are not the same thing. MySQL is database server software; SQL is the language used to communicate with that software. Other RDBMS products also use SQL. Their SQL implementations can differ in available features, syntax details, functions, and administrative commands.

Basic SELECT Structure

A common SQL query follows this pattern:

SELECT column_name
FROM table_name
WHERE condition;
  • SELECT identifies the columns to return.
  • FROM identifies the table from which to retrieve data.
  • WHERE limits the result to rows that satisfy a condition.

Example: Find Customers in Berlin

Suppose a customers table has name and city columns. This query retrieves the names of customers whose city is Berlin:

SELECT name FROM customers WHERE city = 'Berlin';
  • SELECT name asks for the name column.
  • FROM customers says to read the data from the customers table.
  • WHERE city = 'Berlin' keeps only rows whose city matches Berlin.
  • 'Berlin' is a quoted string value.
  • The result is returned as rows and can contain zero, one, or many matching rows.

Common Uses of MySQL

MySQL is a common choice for web applications. An application sends requests to MySQL to save, find, or change information. Typical application data includes:

  • Users, profiles, and login-related records
  • Products, prices, categories, and inventory
  • Posts, pages, comments, and tags
  • Orders, payments, and shipping information
  • Application settings and preferences
  • Sessions and other short-lived application state

Content management systems such as WordPress or Drupal can use MySQL, and forum software such as phpBB can use it as well. The exact database choice depends on the application's version, configuration, hosting environment, and deployment options; a named application does not necessarily use MySQL in every installation.

MySQL in the Web Application Stack

The LAMP stack is a commonly discussed web stack consisting of:

  • Linux: the operating system
  • Apache: the web server
  • MySQL: the data-storage layer
  • PHP: the programming language used by the application

In a typical LAMP application, a browser sends a request to Apache. PHP runs application logic and communicates with MySQL. MySQL stores and retrieves structured data, and PHP uses the result to produce a response.

MySQL is not limited to this stack. It can run with other operating systems, web servers, and programming languages, including applications written in languages such as Python, Java, JavaScript, or Ruby.

Licensing and Availability

MySQL is available under the GNU General Public License (GPL). The GPL is an open-source software license. In general, open source means that source code is available and that people receive rights defined by the applicable license to use, study, modify, and share the software under its conditions.

Licensing obligations can depend on how software is used, combined, modified, or distributed. This overview is educational information, not legal advice. Review the applicable license and obtain professional advice when a project's licensing requirements matter.

MySQL is broadly available for common operating systems and environments, including Windows, Linux, macOS, Solaris, and FreeBSD where supported by the relevant release and distribution.

How MySQL Is Administered

MySQL can be managed through a command-line interface or a graphical administration tool.

A command-line interface is a text-based method for connecting to the server, running SQL, inspecting databases, and automating repeated tasks. It is useful for quick queries, scripts, remote administration, and troubleshooting. A generic connection example is:

mysql -u username -p

This is only an example of the client command, not a complete setup procedure. The host, port, credentials, and database selection vary by environment.

A GUI, or graphical user interface, lets users browse schemas, inspect table definitions, write queries, and sometimes edit records visually. Beginners may prefer a GUI while learning table structures, whereas experienced developers often use both interfaces. The command line and GUI interact with the same underlying MySQL server.

MySQL Compared with Other RDBMS Products

MySQL is one member of the broader RDBMS category. Oracle Database and Microsoft SQL Server are other examples. These products share core concepts such as tables, rows, columns, keys, relationships, and SQL queries.

Concept or productWhat it isRelationship to MySQL
SQLA language for defining and working with relational data.MySQL implements SQL, with its own supported syntax and features.
MySQLA relational database management system.Provides a server, storage, security, SQL processing, and administration features.
Oracle DatabaseAnother relational database product.Uses SQL concepts but differs in features, administration, licensing, and dialect details.
Microsoft SQL ServerAnother relational database product.Uses SQL concepts but differs in features, administration, licensing, and performance characteristics.

Products can differ in supported data types, indexing, transaction behavior, built-in functions, tools, licensing models, performance characteristics, and SQL dialect details. SQL knowledge transfers well between systems, but SQL written for one product may require changes on another.

Troubleshooting Beginner Problems

Confusing MySQL with SQL

If MySQL and SQL seem interchangeable, separate the product from the language: MySQL is database server software, while SQL is the language used to request and manage relational data.

A SELECT Query Returns No Rows

No rows may match the filter, the value may have different spelling, or the query may target the wrong table, database, or column. Check the selected database and column name, inspect some table contents, and try a less restrictive query before adding the WHERE condition again. Case behavior can also depend on the database configuration and comparison context.

An Application Cannot Connect

Confirm that the MySQL service is running. Then verify the host, port, username, password, and database name. If those values are correct, check whether the database user has the required permissions and review the server or application error logs.

Repeated Data Appears Across Tables

Repeated data can indicate that related entities were placed together instead of being modeled separately. Consider separate tables and connect them with primary and foreign keys where appropriate. This can reduce duplication and make updates more consistent.

Key Takeaways

  • MySQL is an RDBMS used to manage structured data.
  • A MySQL server can host multiple individual databases.
  • The relational model organizes data into related tables of rows and columns.
  • Primary keys identify rows, and foreign keys connect related tables.
  • SQL is a language, not the same product as MySQL.
  • MySQL is commonly used as the data layer for websites and other applications.
  • It can be administered through command-line clients or graphical tools.
  • MySQL shares relational concepts with products such as Oracle Database and Microsoft SQL Server, but implementations differ.

For a concise reference, return to this introduction to MySQL as you continue learning SQL and database design.