Here’s a MariaDB FAQ (Frequently Asked Questions) covering common topics and queries related to MySQL installation, usage, and troubleshooting:
To log in to MySQL, use the following command:
mysql -u [username] -p
Replace [username]
with the name of the user you want to log in as. You’ll be prompted to enter the user’s password.
To log out of MySQL, use the following command:
exit
To create a new database, use the following command:
CREATE DATABASE [database_name];
Replace [database_name]
with the name you want to give your new database.
To use a particular database, use the following command:
USE [database_name];
Replace [database_name]
with the name of the database you want to use.
To create a new table in the current database, use the following command:
CREATE TABLE [table_name] (
[column1_name] [data_type],
[column2_name] [data_type],
...
);
Replace [table_name]
with the name you want to give your new table. Replace [column1_name]
and [column2_name]
with the names of the columns you want to create, and replace [data_type]
with the data type for each column.
To view the structure of a table, use the following command:
DESCRIBE [table_name];
Replace [table_name]
with the name of the table you want to describe.
To insert data into a table, use the following command:
INSERT INTO [table_name] ([column1_name], [column2_name], ...) VALUES ([value1], [value2], ...);
Replace [table_name]
with the name of the table you want to insert data into. Replace [column1_name]
, [column2_name]
, and so on with the names of the columns you want to insert data into, and replace [value1]
, [value2]
, and so on with the values you want to insert.
To retrieve data from a table, use the following command:
SELECT [column1_name], [column2_name], ... FROM [table_name];
Replace [column1_name]
, [column2_name]
, and so on with the names of the columns you want to retrieve data from, and replace [table_name]
with the name of the table you want to retrieve data from.
To update data in a table, use the following command:
UPDATE [table_name] SET [column1_name] = [new_value1], [column2_name] = [new_value2], ... WHERE [condition];
Replace [table_name]
with the name of the table you want to update data in. Replace [column1_name]
, [column2_name]
, and so on with the names of the columns you want to update, and replace [new_value1]
, [new_value2]
, and so on with the new values you want to set. Replace [condition]
with a condition that identifies the rows you want to update.
To delete data from a table, use the following command:
DELETE FROM [table_name] WHERE [condition];