MySQL Fundamentals: From Core Concepts to Deployment
This article explains MySQL and relational database fundamentals in a practical, structured way. Instead of starting with commands, it covers why databases exist, how they are organized, and how to deploy them. You will learn the difference between a database and a database management system, the file model versus the service model, keys and constraints, the four core infrastructure areas, relational versus non-relational models, installation options, user@host accounts, least privilege, storage engines, and the files and system databases involved in backup and recovery. The goal is to help you reason through common operations rather than memorize syntax.
Introduction: Why You Should Not Start by Typing Commands
Many developers begin learning databases with a single query. It works during the lesson, but a few weeks later it is forgotten. When performance problems, connection errors, or accidental data deletion appear, there is no foundation to fall back on. The root cause is that commands are surface-level syntax. The real structure of a database is how data is organized, accessed concurrently, isolated for security, and recovered.
A more reliable learning sequence has three stages:
- Why it exists—what core problem it solves;
- What it consists of—concepts, structure, and runtime form;
- How to deploy it—installation, initialization, accounts, and file layout.
This article follows that order. It is divided into four parts and fourteen key difficult points, so that after reading it you can derive most common operations yourself.
Chapter 1: A Database Is Not Just a Large Spreadsheet File
1.1 Core Difference: An Exclusive File vs. a Shared Service
If your only experience is with spreadsheet software, your first impression of a database is often “a table that stores many rows.” That is not wrong, but it misses the most important part: a database does not solve “can it store enough data.” It solves “can many people read and write at the same time without creating chaos.”
- File model: You open it and basically own it. If two people modify it at the same time, the last save overwrites the previous one. Conflicts can only be resolved by manual agreement.
- Service model: A resident process listens on a port. Hundreds or thousands of clients connect over the network and issue reads and writes. The server schedules, locks, and isolates them so they do not corrupt each other.
The difference is not capacity. It is concurrency and order. Around this core, databases also solve three additional problems:
- Types and constraints: Column types, nullability, uniqueness, and value ranges reject invalid writes at the entry point;
- Query efficiency: Index structures locate data quickly at the scale of tens of millions of rows or more, instead of scanning row by row;
- Recoverability: Logs and backups provide a way back after mistakes, power failures, or process crashes.
Only when these four capabilities come together can something be called a database management system.
Difficult Point 1-1: A database and a database management system are two different concepts. The former refers to “a repository that organizes, stores, and manages data according to a certain structure.” The latter refers to “the software that manages this repository.” In everyday speech, “install a database” almost always means installing the management software, not the data itself. Mixing the two is not fatal, but you must distinguish them in documentation and design.
1.2 Five Characteristics and Nine Uses Are Essentially the Same Thing
Textbooks often list several characteristics of databases (structured, low redundancy, independence, controllability, shareability) and several uses (online transaction processing, reporting and analysis, content storage, configuration centers, and so on). They look like two separate lists, but both answer the same question: how to let multiple applications and multiple users safely share one set of data over the long term.
- Structured: Data is defined by structure before it is written, so the meaning is clear;
- Low redundancy: The same fact is stored in only one place, avoiding inconsistency across multiple locations;
- Independence: The logical structure is decoupled from physical storage, so changing storage does not affect applications;
- Controllability: Permissions, transactions, and constraints together ensure “who can change what, how it is changed, and what happens when it is changed incorrectly”;
- Shareability: Concurrency control makes sharing possible.
1.3 Three Terms: Database, Table, Row, and Column
- Database: A namespace and permission boundary for a group of tables;
- Table: A two-dimensional collection with a fixed column structure and variable rows;
- Row (record): A complete description of one business entity;
- Column: One attribute with its type and constraints.
1.4 Primary Keys and Foreign Keys: Identity and Reference
- Primary key: Uniquely identifies a row. It is non-null and non-duplicated, and it is the basis for row-level locating and index organization;
- Foreign key: Declares a reference relationship between tables. It ensures that “the referenced object must exist” and lets the database handle cross-table consistency.
In practice, you should also understand the cost of foreign keys: writes require validation, deletes are constrained, and bulk imports become slower. In high-concurrency scenarios, teams often switch to “application-level consistency plus logical deletion.” This is a tradeoff, not laziness.
1.5 Four Infrastructure Areas
Four types of infrastructure support the capabilities above: the storage engine (how data is written to disk), transactions and logs (how to ensure all-or-nothing), index structures (how to find data quickly), and permissions and metadata (who can access data and what the structure looks like).
Chapter 2: Relational vs. Non-Relational: Hard Requirements of the Two-Dimensional Table and Selection
2.1 Three Hard Requirements of a Two-Dimensional Table
To judge whether a system is relational, look at three points:
- Data is organized as two-dimensional tables, and columns have types;
- Rows can be uniquely located by keys;
- Tables can establish relationships through references, and constraints maintain consistency.
2.2 Four Types of Non-Relational Models
- Key-value: Access values by key. Reads and writes are extremely fast, suitable for caching and sessions;
- Document: Uses semi-structured documents as the unit. The structure is flexible, suitable for business with changing forms;
- Column-family: Aggregates by column family, suitable for large-scale writes and wide-table analysis;
- Graph: Expresses relationships with vertices and edges, suitable for multi-hop association queries.
2.3 How to Choose: Ask Four Questions First
- Is the structure stable? If stable, choose relational. If it changes often, consider document;
- Do you need cross-row transactions? Strong transaction requirements favor relational;
- Is the access pattern point lookup or multi-hop? Point lookup can use key-value, multi-hop can consider graph;
- How do you trade off scale and consistency? If you can accept eventual consistency, then consider distributed solutions.
Conclusion: The vast majority of business systems still use relational databases as the core storage, with non-relational databases as a supplement rather than a replacement.
Chapter 3: Installing the Database: Versions, Installation Methods, Accounts, and Files
3.1 Community Edition vs. Commercial Edition
The community edition is feature-complete and suitable for learning and general business. The commercial edition usually provides additional management, diagnostic, and security capabilities. The choice depends on compliance, service, and budget, not on “which one is stronger.”
3.2 Three Installation Methods
- Install with the system package manager: Easy to upgrade and uninstall, suitable for single machines and development environments;
- Extract and initialize a generic binary package: Paths are controllable, suitable for scenarios that need multiple instances;
- Containerized deployment: Consistent environment and fast start/stop, suitable for testing and elastic scenarios. In production, pay attention to data volume persistence, resource limits, and health checks at the orchestration layer.
3.3 The user@host Form of Accounts
An account is determined by “username + source host.” Therefore, the same username connecting from different hosts is a different principal. When granting permissions, follow least privilege: give the application account only the necessary CRUD permissions, not global management permissions. Keep management accounts separate from business accounts.
Example (only to show the structure, not specific product parameters):
-- Create an application account that can connect only from localhost and grant privileges on a single databaseCREATE USER 'app'@'localhost' IDENTIFIED BY '******';GRANT SELECT, INSERT, UPDATE, DELETE ON biz.* TO 'app'@'localhost';
3.4 Storage Engines: The Source of a Table’s Capabilities
Different storage engines make different tradeoffs in transactions, lock granularity, crash recovery, and full-text search. Choose a transactional engine when you need transactions and foreign keys. For read-only log scenarios, you can choose a lighter option. The engine is specified when creating a table. Changing it after data exists is expensive, so plan ahead.
3.5 Disk Files and Four Built-In Databases
Data on disk usually involves data files (table data), index files, log files (redo/undo/binlog, etc.), and configuration files. Understanding which files hold data and which hold logs is the prerequisite for backup and recovery.
After installation, several system databases are included. They handle metadata, permissions, runtime information, and tool support. The principle is simple: do not manually modify the contents of system databases. All changes should go through a controlled process.
Chapter 4: Overview of Difficult Points and Self-Test
Quick Review of the Fourteen Difficult Points: the difference between a database and a management system, the difference between files and services, five characteristics, primary and foreign keys, four infrastructure areas, three requirements of the two-dimensional table, four non-relational models, four selection questions, version selection, three installation methods, user@host, least privilege, storage engine tradeoffs, files and system databases.
Five Self-Test Questions:
- Why is “two people modifying the same data at the same time” the core problem a database solves?
- What do primary keys and foreign keys each guarantee? Why should foreign keys be used cautiously under high concurrency?
- When should you choose a document model instead of a relational one?
- What does the account user@host mean, and how do you implement least privilege?
- Before backup and recovery, which types of files must you understand first?
Conclusion
Once you establish the five terms “database, table, engine, account, and metadata,” commands are just their syntactic shell. If you want to apply this knowledge in production, you can further combine general cloud capabilities (such as backup storage, log services, and monitoring and alerting) to build an observable and recoverable system. In general practices on platforms such as Baidu AI Cloud, it is also recommended to proceed with the baseline of “clear structure, least privilege, and verifiable backups.”
