fbpx
Learn to build large language model applications: vector databases, langchain, fine tuning and prompt engineering. Learn more

MySQL

avatar-180x180
Ivan Smetannikov

MySQL is a popular database management system that is used globally and across different domains. In this article, you will learn more about how it works, where it is used, and how to work with MySQL.

What is MySQL?

MySQL is widely used by web developers and large companies for storing and managing data. It is one of the most popular database management systems (DBMS) globally that supports all major operating systems: Linux, macOS, and Windows.

Databases are stored on a server, which is typically a remote computer or a cloud server. When you need data, you send a query to the server using your computer, or client, and you receive the information. To manage queries, a special language called Structured Query Language (SQL) is used.

 

Large language model bootcamp

Imagine you have an online clothing store. You need to keep track of all your products, customers, and sales. MySQL can be used for this purpose.

In the DBMS, separate tables are created for products, customers, and sales. The first table stores information about each product, such as its name, price, and available quantity. The second table contains names, contact information, and payment details. The third table holds information about customers who purchased the product, sale dates, and purchased item names.

If you want to know how many sales occurred and who bought products last month, you write a query, send it to the server, and get a list of the relevant data.

 

Understand the database dilemma of SQL vs NoSQL

 

MySQL enables storing and processing information, especially crucial when dealing with large amounts of data. A small store with one seller may record everything in an Excel spreadsheet. Still, for a large network with hundreds of daily purchases, this approach becomes inconvenient.

However, MySQL is not only used in retail but in any context where data is involved.

What is SQL?

To communicate with a database, you need to know its language – SQL, which stands for Structured Query Language. Each query must follow a specific structure for the database to understand you.

At the beginning of the query, there is an action – delete, select, add, followed by a keyword indicating from which table to extract information. Further, there is a statement explaining which details and from which cell of the table to retrieve. The query may also include a condition at the end: for example, the action will be performed only under specific circumstances.

 

Understanding the general query structure for a database management system
Understanding the general query structure for a database management system

 

Queries are entered through the terminal – for this, you need to download a specific program. With its help, you can create and modify tables, link them, add and delete data, and find what you need.

Here’s an SQL crash course for a beginner to explore.

 

 

What is MySQL used for?

With MySQL, you can store any type of data: text, numbers, images, audio and video files, and graphics. Thanks to the system’s performance, even very large volumes of data can be stored, and everything will still function normally. Obtaining the required information can be quick if you know how to use SQL.

MySQL addresses the issue of multiple users when several users are modifying data in the database simultaneously, and only one version is saved. When a user connects to MySQL, the server creates a new entry for them in the metadata table, containing information about the connection state, including the current transaction, if any. This ensures that the data is kept up-to-date.

 

Here’s a guide to understanding different types of databases

 

Additionally, MySQL uses a system of locks to control access to data. When a user tries to access a table, MySQL checks if the table is locked by another user. If the table is locked, the user must wait until the lock is released. This prevents data from being overwritten, and nothing is lost.

Different permissions allow server administrators to manage users’ access to various functions and data. For example, access can be granted only to the data necessary for work, enhancing data storage security.

Who uses MySQL?

Here are a few examples of how large companies use MySQL:

Tesla uses MySQL to store and process data about its cars, including battery status, mileage, speed, and other parameters. MySQL allows Tesla to quickly access this data and analyze it to improve the performance and safety of their cars.

Netflix stores data about its users, such as viewing history, preferences, and recommendations, using a DBMS. This tool helps the company improve its recommendations and personalize content.

PayPal utilizes MySQL to collect and store transaction information, using this data to enhance the security and efficiency of payments.

Essentially, MySQL can be applied in any application or web service, be it an online cinema, a store, a blog, or social network.

Advantages of MySQL

These advantages make MySQL one of the most popular and widely used database management systems in the world:

  • It is free to use; MySQL has open-source code.
  • No need to worry about performance; MySQL is optimized to handle a large number of queries.
  • No need to worry about data; MySQL supports backup and restoration mechanisms that ensure data integrity.
  • Applications are easily expandable; MySQL supports various data storage types, table engines (such as InnoDB, and MyISAM), and other features that enable developers to create complex applications.

How is the MySQL database management system structured?

MySQL consists of several components, each serving specific functions:

  • The main component manages all database operations. The MySQL server receives requests from clients, processes them, performs necessary data operations, and returns the results to clients.
  • Mysqld Service. A process running on the server responsible for managing databases. It accepts requests from clients, processes them, performs read and write data operations, manages transactions, and ensures data security.
  • Data Storage. MySQL uses various types of data storage, such as InnoDB, MyISAM, MEMORY, and others, each with specific features designed for certain data types or tasks.
  • Client Applications. Various client applications, such as MySQL Workbench, phpMyAdmin, the MySQL command-line interface, and others, are used to work with MySQL. These applications allow administrators and developers to create, modify, and manage databases through graphical or text interfaces, such as the terminal.

 

Explore the debate between traditional vs vector databases

 

How to work with MySQL

Let’s go through using the database management system step by step.

 

Explore a hands-on curriculum that helps you build custom LLM applications!

 

  • Installation and setup of MySQL
    To work with MySQL, you need to install the database server on your computer or use online hosting. You can download the program from the official Oracle website, especially if you are working on significant projects. However, for educational purposes, I will be using MySQL in the browser.

 

Installation and setup of MySQL
Installation and setup of MySQL

 

  • Creating a database
    Next, you can create databases and tables, add data, execute queries to retrieve information, and much more using SQL. Let’s create a table for friends from a TV show and their professions.

 

Creating a database
Creating a database

 

  • Adding data
    Populate the tables with data using INSERT statements or import data from files.

 

Adding data
Adding data

 

  • Retrieving data
    Use the SELECT statement to extract data from the table. You can perform various queries, filter data, sort, and group results.

 

Retrieving data
Retrieving data

 

  • Updating and deleting data
    Use UPDATE and DELETE statements to modify and remove data from the table.

 

Updating and deleting data
Updating and deleting data

 

  • Run the program by clicking “Run.”
    We see the program’s results on the right. We requested information about a person working in PR and received the answer – Chandler.

 

Run the program
Run the program

 

This is just a general overview of the process of working with MySQL. For more detailed information and to learn about SQL queries, functions, and MySQL capabilities, refer to the MySQL documentation.

Here’s an overview of MySQL, tools you need to interface with the newly set up RDBMS, and a few datasets that can be used to populate a small testing environment.

 

Ruhma Khawaja author
Ruhma Khawaja
| April 6

As data-driven decision-making gains popularity, more tech graduates are learning data science to enter the job market. While Python and R are popular for analysis and machine learning, SQL and database management are often overlooked.

However, data is typically stored in databases and requires SQL or business intelligence tools for access. In this guide, we provide a comprehensive overview of various types of databases and their differences.

Through this guide, we give you a larger picture to get started with your database journey. So, if you are a beginner with no prior experience, this guide is a must-read for you 

What is a database? 

Databases are used to store and organize large amounts of data in a structured way. They are designed to manage and handle large volumes of information efficiently and effectively, making it easy to retrieve, update, and delete data as needed.

In simple terms, it is a collection of data that is organized in a specific way, making it easy to search, sort, and analyze. It is like a digital filing cabinet, where information is stored and accessed by different users, applications, or systems.

There are various types of databases, such as relational, NoSQL, and object-oriented, each with its own unique characteristics and applications. However, the core purpose of any database is to provide a centralized and secure location for storing and managing data, ensuring data consistency and accuracy, and making it accessible to authorized users or applications.

Understanding databases
Understanding databases

Types of databases

There are several types of databases that are used for different purposes. The main types of databases include:

1. Relational databases:

A relational database is the most common type of database used today. It stores data in tables that are related to each other through keys. Each table in a relational database has a unique primary key, which is used to link it to other tables. They use Structured Query Language (SQL) for managing and querying data. Some popular examples of relational databases are Oracle, Microsoft SQL Server, MySQL, and PostgreSQL.

2. NoSQL databases

NoSQL databases are used for unstructured and semi-structured data. They do not use tables, rows, and columns like relational databases. Instead, they store data in a flexible format, such as key-value pairs, document-based, or graph-based. NoSQL are commonly used in big data and real-time applications. Some popular examples of NoSQL databases are MongoDB, Cassandra, and Couchbase.

3. Object-oriented databases

Object-oriented databases store data in objects, which are similar to the objects used in object-oriented programming languages like Java and C#. They allow for complex data relationships and provide a more natural way of storing data for object-oriented applications. They are commonly used in computer-aided design, web development, and artificial intelligence. Some popular examples of object-oriented databases are ObjectDB and db4o.

4. Hierarchical databases

Hierarchical databases organize data in a tree-like structure, with each record having one parent record and many child records. They are suitable for storing data with a fixed and predictable structure. These were popular in the past, but they have been largely replaced by other types of databases. IBM Information Management System (IMS) is a popular example of a hierarchical database.

5. Network databases

Network databases are similar to hierarchical databases, but they allow for more complex relationships between records. In a network database, each record can have multiple parent and child records. They are suitable for storing data with a complex structure that cannot be easily represented in a hierarchical database. They are not widely used today, but some examples include Integrated Data Stores (IDS) and CA-IDMS.

What is RDBMS?

RDBMS stands for Relational Database Management System. It is defined as a type of database management system that is based on the relational model. In an RDBMS, data is organized into tables and relationships between tables, allowing for easy retrieval and manipulation of the information. The most popular RDBMSs include MySQL, Oracle, PostgreSQL, SQL Server, and SQLite. 

  1. MySQLMySQL is an open-source RDBMS that is widely used for web-based applications. It is known for its high performance, reliability, and ease of use. MySQL is compatible with a wide range of operating systems, including Windows, Linux, and macOS.
  2. OracleOracle is a commercial RDBMS that is widely used in enterprise environments. It is known for its high performance, scalability, and security. Oracle is compatible with a wide range of operating systems, including Windows, Linux, and Solaris. 
  3. PostgreSQLPostgreSQL is an open-source RDBMS known for its advanced features, such as support for complex data types, concurrency control, and full-text search. It is widely used in data warehousing, business intelligence, and scientific applications.
  4. SQL ServerSQL Server is a commercial RDBMS developed and maintained by Microsoft. It is known for its high performance, scalability, and security. SQL Server is compatible with Windows operating system only. 
  5. SQLiteSQLite is a small, lightweight RDBMS that is embedded into the application. It is known for its high performance, reliability, and ease of use. SQLite is compatible with a wide range of operating systems, including Windows, Linux, and macOS. 

Database design

Designing a database is a critical step in creating a functional and efficient database system. It involves creating a structure that will organize the data and enable efficient storage, retrieval, and manipulation. The following are the key components of design:

Designing a database

Designing a database involves identifying the data that needs to be stored and organizing it into tables that are related to each other. The tables should be designed in a way that minimizes redundancy and ensures data consistency.

Entity-relationship diagrams (ERD)

An entity-relationship diagram (ERD) is a visual representation of the its structure. It shows the tables, their relationships, and the attributes that are stored in each table. ERDs are essential as they provide a clear and concise view of the database structure.

Normalization

Normalization is the process of organizing data in a database to minimize redundancy and ensure data consistency. It involves breaking down large tables into smaller, more manageable tables that are related to each other. Normalization helps to eliminate data redundancy and ensures that each table contains only the data that is relevant to it.

There are several levels of normalization, with each level building upon the previous level. The most common levels of normalization are:

  1. First Normal Form (1NF)
  2. Second Normal Form (2NF)
  3. Third Normal Form (3NF)
  4. Boyce-Codd Normal Form (BCNF)

Normalization is an important aspect of design as it helps to minimize data redundancy, ensure data consistency, and improve its performance.

What is SQL?

SQL is used to manage and manipulate databases. Whether you are a beginner or a seasoned developer, understanding the basics of this programming language is essential for anyone working with data.  

Types of SQL commands 

First, let us talk about the several types of SQL commands. SQL commands are grouped into four main categories:  

1. Data definition language (DDL) – DDL commands are used to create and modify a database’s structure, such as creating tables, altering table structures, and deleting tables. Some examples of DDL commands include CREATE, ALTER, and DROP. 

2. Data manipulation language (DML) – DML commands are used to manipulate the data within a database. These commands include SELECT, INSERT, UPDATE, and DELETE.  

3. Data control language (DCL) – DCL commands are used to manage access such as granting and revoking permissions. Examples of DCL commands include GRANT and REVOKE. 

4. Data query language (DQL) – Primarily, DQL commands are used to query the data. Most used commands include SELECT which are used to retrieve data from a table. 

Difference between SQL and NoSQL 

One of the main differences between SQL and NoSQL databases is how they store and retrieve data. SQL databases use tables and rows to store the data, while NoSQL databases use documents, collections, or key-value pairs. SQL databases are better suited for structured data, while NoSQL databases are better suited for unstructured data. 

Another difference between SQL and NoSQL databases is the way they handle scalability. As these databases are vertically scalable, SQL databases can handle more load by adding more resources to the same server. NoSQL databases are horizontally scalable and can handle the additional load by adding more servers. 

Interested in learning more about data science? We have you covered. Click on this link to learn more about free Data Science crash courses to help you succeed. 

Conclusion 

In conclusion, this guide provides a comprehensive overview of various types and their differences, including relational, non-relational, object-oriented, hierarchical, and network databases. Designing a database is a critical step in creating a functional and efficient database system. By understanding the types and their unique features, you can choose the right database for your specific use case and design one that meets your data management needs.

Related Topics

Statistics
Resources
Programming
Machine Learning
LLM
Generative AI
Data Visualization
Data Security
Data Science
Data Engineering
Data Analytics
Computer Vision
Career
Artificial Intelligence