MySQL - Databases

In MySQL, a database is a collection of related data that is organized in a structured manner. It is used to store, manage, and retrieve data efficiently. A database consists of one or more tables that are related to each other in some way. The tables contain rows and columns of data.

Each database in MySQL is identified by a unique name. Users can create, modify, and delete databases as required. Once a database is created, it can be populated with data by adding records to the tables.

The concept of a database in MySQL includes several key features, including:

  1. Tables: A table is a collection of related data stored in rows and columns. Each column has a name and a data type, and each row represents a single record.
  2. Fields: A field is a single piece of data in a table. Each field is associated with a column in the table.
  3. Records: A record is a complete set of related data in a table. Each record is associated with a row in the table.
  4. Relationships: A relationship is a connection between two or more tables that allows data to be shared between them. Relationships can be established using primary keys and foreign keys.
  5. Indexes: An index is a data structure that allows data to be retrieved more efficiently. It is created on one or more columns in a table.

Create Database: This command is used to create a new database in MySQL.

CREATE DATABASE mydatabase; 

Drop Database: This command is used to delete a database in MySQL.

DROP DATABASE mydatabase; 

List Databases: This command is used to display a list of all databases in MySQL.

SHOW DATABASES;

Use Database: This command is used to select a database to work with in MySQL.

USE mydatabase;

Rename Database: This command is used to rename a database in MySQL.

ALTER DATABASE mydatabase RENAME TO newdatabase;