{"id":847,"date":"2025-12-19T10:00:06","date_gmt":"2025-12-19T09:00:06","guid":{"rendered":"https:\/\/mybox.com\/help\/?post_type=manual_kb&#038;p=847"},"modified":"2026-02-16T14:01:41","modified_gmt":"2026-02-16T13:01:41","slug":"sample-mysql-commands","status":"publish","type":"manual_kb","link":"https:\/\/mybox.com\/help\/en\/knowledgebase\/sample-mysql-commands\/","title":{"rendered":"Sample MySQL commands"},"content":{"rendered":"\n<div class=\"translation-block translation-block-merged\">\n<p class=\"wp-block-paragraph\">MySQL is a popular database management system that is widely used to store and manage data in various applications and websites. In this article, we&#8217;ll discuss some key example MySQL commands that are essential for creating, managing, and executing database queries.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_86 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/sample-mysql-commands\/#1_Creating_a_database\" >1. Creating a database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/sample-mysql-commands\/#2_Choosing_a_database\" >2. Choosing a database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/sample-mysql-commands\/#3_Create_a_table\" >3. Create a table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/sample-mysql-commands\/#4_Inserting_data\" >4. Inserting data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/sample-mysql-commands\/#5_Update_data\" >5. Update data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/sample-mysql-commands\/#6_Deletion_of_data\" >6. Deletion of data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/sample-mysql-commands\/#7_SELECT_Queries\" >7. SELECT Queries<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/sample-mysql-commands\/#8_Creating_Indexes\" >8. Creating Indexes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/sample-mysql-commands\/#9_Deleting_Tables_and_Databases\" >9. Deleting Tables and Databases<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/sample-mysql-commands\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Creating_a_database\"><\/span>1. Creating a database<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The first step in working with MySQL is to create a database that will store data for our application. We can do this with the command <code>CREATE DATABASE<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE database_name;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Choosing_a_database\"><\/span>2. Choosing a database<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<\/div>\n\n<div id=\"mybox-373731412\" class=\"mybox-content mybox-entity-placement\"><div class=\"early-access-banner-inpost\">\r\n  <div class=\"banner-left-inpost\">\r\n    <div class=\"icon-box-inpost\">\r\n      <img decoding=\"async\" src=\"https:\/\/mybox.com\/help\/wp-content\/uploads\/2026\/02\/square-info-icon.svg\" alt=\"Info\">\r\n    <\/div>\r\n    <div class=\"text-box-inpost\">\r\n      <span class=\"label-inpost\"><span class=\"translation-block translation-block-banner-text\">Early access<\/span><\/span>\r\n      <h4><span class=\"translation-block translation-block-banner-text\">Still need help?<\/span><\/h4>\r\n      <p><span class=\"translation-block translation-block-banner-text\">Contact our customer service team.<\/span><\/p>\r\n    <\/div>\r\n  <\/div>\r\n\r\n  <div class=\"banner-right-inpost\">\r\n    <a href=\"https:\/\/panel.mybox.com\/helpdesk2\/v\/list\/\" class=\"banner-button-inpost\"><span class=\"translation-block translation-block-banner-text\">Message us<\/span><\/a>\r\n  <\/div>\r\n<\/div><\/div>\n\n<div class=\"translation-block translation-block-merged\"><p class=\"wp-block-paragraph\">To start working on a particular database, we need to select it. The <code>USE<\/code> command allows us to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>USE database_name;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Create_a_table\"><\/span>3. Create a table<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Tables are the primary way to store data in a database. We can create a table using the . Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE employees (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    first name VARCHAR(50),\n    surname VARCHAR(50),\n    age INT\n);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Inserting_data\"><\/span>4. Inserting data<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To insert data into a table, we use the <code>INSERT INTO<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO employees (first name, surname, age) VALUES ('John', 'Smith', 30);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Update_data\"><\/span>5. Update data<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If we need to update the existing data in the table, we use the <code>UPDATE<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>UPDATE employees SET age = 31 WHERE id = 1;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Deletion_of_data\"><\/span>6. Deletion of data<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Command <code>DELETE<\/code> Used to delete data from a table. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DELETE FROM employees WHERE id = 2;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_SELECT_Queries\"><\/span>7. SELECT Queries<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To retrieve data from a table, we use the <code>SELECT<\/code>. Below is an example of a query:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM employees WHERE age > 25;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This example will return all records from the &#8220;employees&#8221; table where the age is greater than 25 years old.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8_Creating_Indexes\"><\/span>8. Creating Indexes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Indexes allow you to speed up database queries. We can create an index using the command <code>CREATE INDEX<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE INDEX idx_age ON employees (age);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"9_Deleting_Tables_and_Databases\"><\/span>9. Deleting Tables and Databases<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To delete a table, we use the <code>DROP TABLE<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DROP TABLE employees;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To delete a database, we use the command <code>DROP DATABASE<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DROP DATABASE database_name;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL offers many useful commands for database management. It is worth knowing the basic ones in order to effectively create, update and retrieve data from the database. As you gain experience, you can learn more advanced operations and query optimization. MySQL is a powerful tool for working with data, which is used in many areas of computer science and business.<\/p>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"template":"","format":"standard","manualknowledgebasecat":[9,25],"manual_kb_tag":[968,1655,1108,1656,1641,1657,1642,1658,1643,1659,1644,1660,1645,1646,1647,1648,1649,1650,214,1651,801,1652,802,1653,808,1654],"class_list":["post-847","manual_kb","type-manual_kb","status-publish","format-standard","hentry","manualknowledgebasecat-databases","manualknowledgebasecat-hosting","manual_kb_tag-databases","manual_kb_tag-database-administration","manual_kb_tag-database","manual_kb_tag-sql-examples","manual_kb_tag-mysql-commands","manual_kb_tag-crud-operations","manual_kb_tag-mysql-tutorial","manual_kb_tag-employees-table","manual_kb_tag-database-management","manual_kb_tag-sql-commands","manual_kb_tag-select-database","manual_kb_tag-table-creation","manual_kb_tag-create-table","manual_kb_tag-insert-data","manual_kb_tag-update-data","manual_kb_tag-delete-data","manual_kb_tag-select-queries","manual_kb_tag-sql-queries","manual_kb_tag-create-database","manual_kb_tag-database-queries","manual_kb_tag-mysql","manual_kb_tag-create-index","manual_kb_tag-database-management-system","manual_kb_tag-drop-table","manual_kb_tag-query-optimization","manual_kb_tag-drop-database"],"_links":{"self":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":1,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/847\/revisions"}],"predecessor-version":[{"id":5983,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/847\/revisions\/5983"}],"wp:attachment":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/media?parent=847"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manualknowledgebasecat?post=847"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb_tag?post=847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}