What are some of the common MySQL commands?
MySQL is a popular open-source relational database management system, and it uses SQL (Structured Query Language) for managing and manipulating data. Here are some common MySQL commands:
-
Logging into MySQL:
codemysql -u username -p
This command allows you to log into MySQL. Replace
username
with your MySQL username. You will be prompted to enter your password. -
Creating a Database:
sql codeCREATE DATABASE database_name;
This command creates a new database with the specified name.
-
Selecting a Database:
codeUSE database_name;
This command selects a specific database to work with.
-
Creating a Table:
sql codeCREATETABLE table_name ( column1 datatype, column2 datatype, ... );
This command creates a new table with specified columns and data types.
-
Inserting Data:
sql codeINSERTINTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
This command inserts new rows of data into an existing table.
-
Querying Data:
sql codeSELECT column1, column2, ... FROM table_name WHEREcondition;
This command retrieves data from a table based on specified conditions.
-
Updating Data:
sql codeUPDATE table_name SET column1 = value1, column2 = value2 WHEREcondition;
This command modifies existing data in a table based on specified conditions.
-
Deleting Data:
sql codeDELETEFROM table_name WHEREcondition;
This command deletes data from a table based on specified conditions.
-
Adding a New Column to a Table:
sql codeALTERTABLE table_name ADD column_name datatype;
This command adds a new column to an existing table.
-
Modifying a Column in a Table:
sql codeALTERTABLE table_name MODIFY column_name datatype;
This command modifies the data type of an existing column in a table.
-
Dropping a Table:
sql codeDROPTABLE table_name;
This command deletes an existing table along with all its data.
-
Dropping a Database:
sql codeDROP DATABASE database_name;
This command deletes an existing database along with all its tables and data.
Remember that executing some of these commands can result in data loss, so always be cautious and make sure you have appropriate backups before making significant changes to your database.
Comments
Post a Comment