About MySQL
Why MySQL Is Used?
When It Is Used?
Types of Command In MySQL
CREATE: Creates new databases, tables, views, indexes, or stored procedures.
ALTER: Modifies existing database objects like tables, adding or removing columns, changing data types, etc.DROP: Deletes databases, tables, views, or indexes from the database.TRUNCATE: Removes all data from a table, resetting its structure.
Data Manipulation Language (DML) Commands: These commands are used to manipulate data within database objects.
SELECT: Retrieves data from one or more tables based on specified conditions.INSERT: Adds new rows of data into a table.UPDATE: Modifies existing data in a table based on specified conditions.DELETE: Removes rows of data from a table based on specified conditions.
Data Control Language (DCL) Commands: These commands manage access permissions and control privileges within the database.
GRANT: Provides specific privileges to users or roles within the database.REVOKE: Removes specified privileges from users or roles.
Data Query Language (DQL) Command:
SHOW: Displays information about databases, tables, columns, or server status.
Here's a more detailed breakdown:
Transaction Control Language (TCL) Commands: These commands manage transactions within the database, ensuring data integrity.
COMMIT: Saves the changes made during the current transaction to the database.
ROLLBACK: Undoes the changes made during the current transaction, reverting to the last committed state.
SAVEPOINT: Sets a named point within a transaction to which you can later roll back.
SET: Modifies the session-specific configuration settings, like setting variables or adjusting behavior.
Utility Commands:
USE: Selects a particular database to work with among multiple databases in the MySQL server.
DESCRIBE or DESC: Shows the structure of a table, including column names, types, and constraints.
EXPLAIN: Provides information about the execution plan of a SELECT query, showing how MySQL executes it.
HELP: Retrieves information and help about MySQL commands and functions.
Miscellaneous Commands:
QUIT or EXIT: Exits the MySQL command-line interface.
SOURCE: Executes SQL statements from a file within the MySQL client.
Here are some additional commands used in MySQL:
Index Related Commands:
CREATE INDEX: Creates an index on a table for faster data retrieval.
DROP INDEX: Removes an index from a table.
User Account Management Commands:
CREATE USER: Creates a new user account with specified privileges.
ALTER USER: Modifies the properties or privileges of an existing user account.
DROP USER: Deletes a user account.
SET PASSWORD: Changes the password for a MySQL user account.
Server Administration Commands:
SHOW VARIABLES: Displays the current MySQL server configuration variables.
SHOW STATUS: Provides server status information like uptime, connections, and more.
SHOW PROCESSLIST: Shows the currently running processes/queries on the server.
FLUSH: Reloads or resets certain server configurations or caches.
Replication and Clustering Commands:
CHANGE MASTER TO: Configures a replication master server.
START SLAVE: Initiates replication on a slave server.
STOP SLAVE: Halts replication on a slave server.
CREATE/DROP/ALTER CLUSTER: Commands related to cluster management in MySQL Cluster configurations.
Event Scheduler Commands:
CREATE EVENT: Defines a new event, specifying a schedule and associated actions to be executed automatically.
ALTER EVENT: Modifies the characteristics of an existing event.
DROP EVENT: Removes a scheduled event from the database.
Partitioning Commands:
ALTER TABLE ... ADD PARTITION: Splits an existing table into partitions based on defined criteria.
ALTER TABLE ... DROP PARTITION: Removes partitions from a partitioned table.
Full-Text Search Commands:
MATCH ... AGAINST: Enables full-text searches in MySQL for matching keywords against indexed columns in tables.
BOOLEAN MODE: Specifies a mode for full-text searches allowing logical operators and certain modifiers.
JSON Data Type Commands:
JSON_OBJECT: Constructs JSON objects within SQL statements.
JSON_ARRAY: Constructs JSON arrays within SQL statements.
JSON_EXTRACT: Extracts data from a JSON document based on a specified path expression.
Geospatial Data Commands:
ST_GeometryType: Returns the geometry type of a spatial object.
ST_Distance: Calculates the distance between two geometries.
ST_Contains: Checks if one geometry contains another.
Information Schema Commands:
INFORMATION_SCHEMA: Provides access to metadata about the MySQL server and databases, allowing users to query information about tables, columns, indexes, privileges, and more.
Binary Log Commands:
SHOW BINARY LOGS: Displays a list of available binary log files.
PURGE BINARY LOGS: Removes binary log files to free up space or to clean up old logs.
Debugging and Profiling Commands:
SET PROFILING: Enables profiling for the current session, allowing users to analyze query performance.
SHOW PROFILES: Displays a list of recent statements executed along with their resource consumption details.
Resource Limit Commands:
SET GLOBAL: Sets global system variables related to resource limits, such as maximum connections, query execution time, etc.
SHOW GLOBAL VARIABLES: Retrieves and displays global system variable settings.
Server Audit Commands:
AUDIT: Enables or disables auditing for specific server activities, allowing the tracking of various events like logins, database accesses, and more.
INSTALL PLUGIN: Installs an audit plugin to enable logging of specific activities.
XML Functions:
ExtractValue(): Retrieves data from an XML string based on XPath expressions.
UpdateXML(): Modifies XML data within a string using XPath expressions.
XQuery(): Executes XQuery expressions on XML data.
Common Table Expressions (CTE):
WITH ... AS: Defines temporary named result sets within a SELECT statement.
RECURSIVE: Allows recursive queries within CTEs to handle hierarchical data.
Window Functions:
ROW_NUMBER(): Assigns a unique sequential integer to each row within a partition of a result set.
RANK(), DENSE_RANK(): Computes the rank of rows within partitions based on specified criteria.
User-Defined Functions (UDF):
CREATE FUNCTION: Defines custom functions using SQL or external languages like C/C++ to extend MySQL functionalities.
DROP FUNCTION: Removes a user-defined function from the database.
Data Encryption Commands:
AES_ENCRYPT(), AES_DECRYPT(): Encrypts and decrypts data using the AES algorithm within MySQL queries.
Backup and Restore Commands:
mysqldump: A command-line tool used to back up MySQL databases, generating SQL files containing database structure and data.
mysqlimport: A command-line utility to import data from text files into MySQL databases.
mysqlpump: A backup utility that creates logical backups, offering parallel processing for faster backups.
Performance Tuning Commands:
EXPLAIN: Analyzes SELECT queries to provide insights into the query execution plan and optimizations.
OPTIMIZE TABLE: Reorganizes table data and defragments indexes for better performance.
ANALYZE TABLE: Updates table statistics, helping the query optimizer generate more efficient execution plans.
Connection Management Commands:
SHOW PROCESSLIST: Displays information about active connections and running queries.
KILL: Terminates a specific MySQL thread/connection.
Character Set and Collation Commands:
SET NAMES: Specifies the character set and collation for client-server communication.
ALTER DATABASE ... CHARACTER SET: Changes the default character set of a database.
Remote Management Commands:
GRANT ALL PRIVILEGES: Grants all privileges on a database or tables to a specific user from a remote location.
FLUSH HOSTS: Clears the host cache, allowing reconnection attempts from remote hosts.
Locking Commands:
LOCK TABLES: Locks tables explicitly to prevent multiple users from accessing them simultaneously for write operations.
UNLOCK TABLES: Releases table locks acquired by the LOCK TABLES command.
Error Handling Commands:
DECLARE ... HANDLER: Specifies handlers to deal with specific error conditions that might occur during execution.
SIGNAL: Raises an error condition and passes an error message back to the client.
Resource Group Management Commands:
CREATE RESOURCE GROUP: Defines resource groups to manage system resources.
SET RESOURCE GROUP: Assigns sessions to specific resource groups.
Audit Log Commands:
INSTALL COMPONENT: Enables the Audit Log Plugin to log specific server activities.
SET GLOBAL audit_log: Configures the audit log plugin settings.
Optimizer Hint Commands:
Check Constraints (Starting from MySQL 8.0.16):/*+ HINT */: Allows users to provide optimizer hints within SQL statements to influence query execution plans.
CHECK: Adds constraints to enforce specific conditions on column values within a table.
Temporary Table Commands:
CREATE TEMPORARY TABLE: Creates a temporary table that exists for the duration of a session.
DROP TEMPORARY TABLE: Removes a temporary table explicitly.
Row-Level Security (RLS) Commands (Starting from MySQL 8.0.23):
CREATE|ALTER|DROP POLICY: Defines, modifies, or removes security policies for controlling access to rows.
SET ROLE: Sets the current session role for row-level access control.
Invisible Indexes Commands (Starting from MySQL 8.0.23):
ALTER TABLE ... ALTER INDEX ... INVISIBLE: Makes an index invisible to the optimizer for query planning.
ALTER TABLE ... ALTER INDEX ... VISIBLE: Makes an invisible index visible again for optimization purposes.
Resource Management Commands (Starting from MySQL 8.0.18):
CREATE RESOURCE GROUP: Defines resource groups for managing and allocating server resources.
ALTER INSTANCE ROTATE INNODB REDO LOGS: Rotates the InnoDB redo log files for crash recovery or replication setup.
Common Table Expressions (CTE) with INSERT, UPDATE, DELETE (Starting from MySQL 8.0.19):
Allows using CTEs with INSERT, UPDATE, and DELETE statements for improved query capabilities.
Spatial Data Commands:
ST_AsText(): Converts spatial data into Well-Known Text (WKT) format.
ST_GeomFromText(): Creates spatial data from Well-Known Text (WKT) representations.
Generated Columns Commands:
VIRTUAL: Defines a generated column that is computed when queried.
STORED: Specifies a generated column that stores computed values physically.
Persistent Auto-Increment Values (Starting from MySQL 8.0.22):
SET PERSIST: Allows setting the auto-increment value persistently for tables.
Time Zone Commands:
SET TIME_ZONE: Sets the time zone for the current session.
CONVERT_TZ(): Converts a datetime value from one time zone to another.
Resource Limiting and Control (Starting from MySQL 8.0.14):
RESOURCE_GROUP: Manages resources by controlling the execution of specific operations within defined groups.
SET SQL_SELECT_LIMIT: Restricts the number of rows returned by a SELECT statement.
Connection Encryption and Compression:
--ssl: Enables SSL encryption for secure connections.
--compress: Enables compression for reducing network traffic.
Row Value Expressions (Starting from MySQL 8.0.19):
ROW(): Creates a row value expression representing a row of values.
VALUES(): Used in INSERT...VALUES statements to specify explicit values for multiple rows.
Recursive Common Table Expressions (Starting from MySQL 8.0.17):
Allows CTEs to perform recursive queries, enabling hierarchical data retrieval or processing.
Optimizer Trace Commands (Starting from MySQL 8.0.18):
SET SESSION optimizer_trace: Enables tracing of the query optimization process.
SHOW SESSION optimizer_trace: Displays the optimizer trace for a specific query.
Histograms for InnoDB Tables (Starting from MySQL 8.0.23):
ANALYZE TABLE: Computes histograms on InnoDB tables for better query optimization.
Password Expiry and Reuse Controls:
ALTER USER ... PASSWORD EXPIRE: Forces a user to change their password upon next login.
ALTER USER ... PASSWORD HISTORY: Specifies the number of recent passwords to be remembered.
Partition Pruning Commands:
PARTITION ... EXCHANGE PARTITION: Swaps partitions between tables for efficient data management.
PARTITION ... TRUNCATE PARTITION: Removes data from a partition, preserving the partition structure.
Tablespace Management Commands:
CREATE TABLESPACE: Creates a new tablespace in MySQL.
ALTER TABLESPACE: Modifies attributes of an existing tablespace.
Group Replication Commands:
START GROUP_REPLICATION: Initiates group replication in a MySQL server group.
STOP GROUP_REPLICATION: Halts group replication on a MySQL server group.
Resource Limitations for Accounts:
CREATE USER ... WITH RESOURCE OPTIONS: Assigns resource limits to specific user accounts.
ALTER USER ... RESOURCE OPTIONS: Modifies resource limits for existing user accounts.
User-Defined Collations:
CREATE COLLATION: Defines custom collations to suit specific sorting and comparison needs.
DROP COLLATION: Removes a user-defined collation from the server.
Persistent Optimizer Statistics (Starting from MySQL 8.0.23):
SET PERSIST_ONLY optimizer_use_*: Makes optimizer statistics persistent without restarting the server.
Enhancements in JSON Support:
JSON_TABLE(): Allows querying JSON data and returning it as a relational table.
Pluggable Authentication:
INSTALL COMPONENT: Enables or installs authentication plugins to enhance security measures.
SHOW PLUGINS: Displays information about installed authentication plugins.
Enhancements in Window Functions:
NTILE(): Divides result sets into specified number of buckets.
LAG(), LEAD(): Accesses data from previous or subsequent rows within a result set.
Table Checksum Commands:
CHECKSUM TABLE: Computes checksums for tables to detect inconsistencies or corruption.
Row-Level Transactions Commands:
START TRANSACTION: Begins an explicit transaction block in MySQL.
COMMIT, ROLLBACK: Commits or rolls back the current transaction's changes.
Delayed Evaluation of Common Table Expressions (Starting from MySQL 8.0.14):
Allows delaying the evaluation of CTEs to optimize query execution.
Replication Delay Management:
CHANGE MASTER TO MASTER_DELAY = N: Introduces a delay in replication to manage data consistency across replicas.