{"id":2665,"date":"2025-04-03T14:56:14","date_gmt":"2025-04-03T14:56:14","guid":{"rendered":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/?p=2665"},"modified":"2025-12-17T10:39:39","modified_gmt":"2025-12-17T10:39:39","slug":"create-mysql-database-by-command-line","status":"publish","type":"post","link":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/444\/create-mysql-database-by-command-line.html","title":{"rendered":"How to Create a Database in MySQL With Command Line?"},"content":{"rendered":"\n<p>MySQL is one of the most widely used database management systems, powering everything from small websites to enterprise applications. In that, creating a database is the first and most crucial step in organising and storing data efficiently. Especially before moving into concepts like <strong><a href=\"https:\/\/chartdb.io\/blog\/data-modeling-and-its-types\" target=\"blank\">data modeling in SQL<\/a><\/strong>. Whether you are setting up a new project, managing an existing application, or working on a remote server, knowing how to create a MySQL database is essential.<\/p>\n\n\n\n<p>While many people prefer using graphical tools like phpMyAdmin or MySQL Workbench to manage databases, there are situations where using the command line is more efficient and even necessary.<\/p>\n\n\n\n<hr><p><strong>Also Read: <\/strong><a href=\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/71\/How-to-create-a-mysql-database-in-cpanel.html\"><strong>How to Create a MySQL Database By Using cPanel?<\/strong><\/a><\/p><hr>\n\n\n\n<p><strong>Scenarios like:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When you are working with cloud servers or VPS, GUI-based tools may not be available.\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The best part is that the command line allows you to automate database tasks through scripts.\u00a0<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Some tasks execute faster through direct command execution rather than clicking through a UI.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Command-line tools are lightweight and do not require additional software.<\/li>\n<\/ul>\n\n\n\n<p>If you&#8217;re comfortable with basic Linux commands, using MySQL through the terminal is straightforward. Let\u2019s walk through the steps to create a MySQL database using the command line!<\/p>\n\n\n\n<p>Before we get started to create a MySQL database from the Command line, let\u2019s know its prerequisites:<\/p>\n\n\n\n<hr><p><strong>Also Read: <\/strong><a href=\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/382\/How-to-Create-a-Database-in-the-Plesk-Panel.html\"><strong>How to Create a Database in the Plesk Panel?<\/strong><\/a><\/p><hr>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Prerequisites to Create a MySQL Database From the Command Line<\/strong><\/h2>\n\n\n\n<p>Before creating a database, you need to ensure that:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You have MySQL installed on your system.<\/li>\n\n\n\n<li>You have access to a MySQL user account with privileges to create databases.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Steps to Create a MySQL Database From the Command Line<\/strong><\/h2>\n\n\n\n<p>\u2794 If your MySQL is not installed, you need to install it by using the following command:<\/p>\n\n\n\n<p><strong>On Ubuntu\/Debian:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>sudo apt update<\/strong><br><strong>sudo apt install mysql-server<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u2794 After installation, start and secure MySQL by using the below command:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>sudo systemctl start mysql<\/strong><br><strong>sudo mysql_secure_installation<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>On CentOS\/RHEL:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>sudo yum install mysql-server<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>sudo systemctl start mysqld<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u2794 Secure MySQL with the following command:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>sudo mysql_secure_installation<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>On macOS:<\/strong><\/p>\n\n\n\n<p>In macOS, you have to use Homebrew to install MySQL:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>brew install mysql<\/strong><br><strong>brew services start mysql<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>On Windows:<\/strong><\/p>\n\n\n\n<p>For Windows, you have to download the MySQL installer from the official <a href=\"https:\/\/dev.mysql.com\/downloads\/installer\/\"><strong>MySQL <\/strong><\/a>website and follow the setup wizard.<\/p>\n\n\n\n<p>Once your MySQL has been installed, it\u2019s time to create a database. Let\u2019s get started!<\/p>\n\n\n\n<p>\u2794 To start using MySQL, you have to open the terminal or command prompt and log in with your MySQL user account by adding the following command.<\/p>\n\n\n\n<p><strong>On Linux\/macOS:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>sudo mysql -u root -p<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>On Windows (Command Prompt):<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>mysql -u root -p<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>After entering the correct password, you will see the MySQL command prompt:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>mysql><\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr><p><strong>Also Read: <\/strong><a href=\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/374\/How-to-Change-MySQL-Database-User-Password-From-cPanel.html\"><strong>How to reset the password for a MySQL database?<\/strong><\/a><\/p><hr>\n\n\n\n<p>\u2794 The time has come to create a database. For this, you have to use the following command to create a database:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>CREATE DATABASE mydatabase;<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>You need to replace it with \u2018<strong>mydatabase\u2019<\/strong>with your database name.<\/p>\n\n\n\n<p>For example, If you are creating a database for an eCommerce project, you might name it <strong>ecommerce_db<\/strong>. In that case, your command will be:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>CREATE DATABASE ecommerce_db;<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u2794 Once the database is created, you need to verify that it was created. For this, you have to use the following command:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>SHOW DATABASES;<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u2794 This will list all databases, and you should see your new database in the list. It will look like this:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; +<\/strong><br><strong>| Database\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 |<\/strong><br><strong>+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; +<\/strong><br><strong>| information_schema|<\/strong><br><strong>| ecommerce_db\u00a0 \u00a0 \u00a0 |<\/strong><br><strong>| mysql \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 |<\/strong><br><strong>| performance_schema|<\/strong><br><strong>| sys \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 |<\/strong><br><strong>+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; +<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u2794 To start using the newly created database, select it by using the following command:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"kb_firewall\"><strong>USE ecommerce_db;<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>That\u2019s it; you have successfully created a database in MySQL with the command line. Now, any tables you create will be part of this database.<\/p>\n\n\n\n<hr><p><strong>Also Read: <\/strong><a href=\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/442\/how-to-create-table-in-mysql.html\"><strong>How to Create a Table in MySQL?<\/strong><\/a><\/p><hr>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Creating a database in MySQL using the command line is an essential skill for developers and system administrators. Whether you are working on a local machine or managing a cloud server, the command line provides a fast, efficient, and flexible way to handle databases.<\/p>\n\n\n\n<p>Now, you are ready to store and manage data efficiently in MySQL!<\/p>\n\n\n\n<p>Happy Coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL is one of the most widely used database management systems, powering everything from small websites to enterprise applications. In that, creating a database is the first and most crucial step in organising and storing data efficiently. Especially before moving into concepts like data modeling in SQL. Whether you are setting up a new project, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57],"tags":[],"class_list":["post-2665","post","type-post","status-publish","format-standard","hentry","category-mysql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Create a Database in MySQL With Command Line?<\/title>\n<meta name=\"description\" content=\"Learn how to create a MySQL database using the command line in Linux, macOS, and Windows with this Step-by-step guide with commands &amp; examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/444\/create-mysql-database-by-command-line.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create a Database in MySQL With Command Line?\" \/>\n<meta property=\"og:description\" content=\"Learn how to create a MySQL database using the command line in Linux, macOS, and Windows with this Step-by-step guide with commands &amp; examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/444\/create-mysql-database-by-command-line.html\" \/>\n<meta property=\"og:site_name\" content=\"Host IT Smart Knowledge base\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-03T14:56:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-17T10:39:39+00:00\" \/>\n<meta name=\"author\" content=\"Admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/444\/create-mysql-database-by-command-line.html\",\"url\":\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/444\/create-mysql-database-by-command-line.html\",\"name\":\"How to Create a Database in MySQL With Command Line?\",\"isPartOf\":{\"@id\":\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/#website\"},\"datePublished\":\"2025-04-03T14:56:14+00:00\",\"dateModified\":\"2025-12-17T10:39:39+00:00\",\"author\":{\"@id\":\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/#\/schema\/person\/317c14a877385667f19d3b7496bd5108\"},\"description\":\"Learn how to create a MySQL database using the command line in Linux, macOS, and Windows with this Step-by-step guide with commands & examples.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/444\/create-mysql-database-by-command-line.html\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/#website\",\"url\":\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/\",\"name\":\"Host IT Smart Knowledge base\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/#\/schema\/person\/317c14a877385667f19d3b7496bd5108\",\"name\":\"Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d4827c56a6721070dde339640d47ff44ba0d0e515c7e577cf29305ab72383fe3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d4827c56a6721070dde339640d47ff44ba0d0e515c7e577cf29305ab72383fe3?s=96&d=mm&r=g\",\"caption\":\"Admin\"},\"sameAs\":[\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/\"],\"url\":\"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Create a Database in MySQL With Command Line?","description":"Learn how to create a MySQL database using the command line in Linux, macOS, and Windows with this Step-by-step guide with commands & examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/444\/create-mysql-database-by-command-line.html","og_locale":"en_US","og_type":"article","og_title":"How to Create a Database in MySQL With Command Line?","og_description":"Learn how to create a MySQL database using the command line in Linux, macOS, and Windows with this Step-by-step guide with commands & examples.","og_url":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/444\/create-mysql-database-by-command-line.html","og_site_name":"Host IT Smart Knowledge base","article_published_time":"2025-04-03T14:56:14+00:00","article_modified_time":"2025-12-17T10:39:39+00:00","author":"Admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Admin","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/444\/create-mysql-database-by-command-line.html","url":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/444\/create-mysql-database-by-command-line.html","name":"How to Create a Database in MySQL With Command Line?","isPartOf":{"@id":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/#website"},"datePublished":"2025-04-03T14:56:14+00:00","dateModified":"2025-12-17T10:39:39+00:00","author":{"@id":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/#\/schema\/person\/317c14a877385667f19d3b7496bd5108"},"description":"Learn how to create a MySQL database using the command line in Linux, macOS, and Windows with this Step-by-step guide with commands & examples.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/444\/create-mysql-database-by-command-line.html"]}]},{"@type":"WebSite","@id":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/#website","url":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/","name":"Host IT Smart Knowledge base","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/#\/schema\/person\/317c14a877385667f19d3b7496bd5108","name":"Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d4827c56a6721070dde339640d47ff44ba0d0e515c7e577cf29305ab72383fe3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d4827c56a6721070dde339640d47ff44ba0d0e515c7e577cf29305ab72383fe3?s=96&d=mm&r=g","caption":"Admin"},"sameAs":["https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/"],"url":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/wp-json\/wp\/v2\/posts\/2665","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/wp-json\/wp\/v2\/comments?post=2665"}],"version-history":[{"count":16,"href":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/wp-json\/wp\/v2\/posts\/2665\/revisions"}],"predecessor-version":[{"id":3941,"href":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/wp-json\/wp\/v2\/posts\/2665\/revisions\/3941"}],"wp:attachment":[{"href":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/wp-json\/wp\/v2\/media?parent=2665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/wp-json\/wp\/v2\/categories?post=2665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostitsmart.com\/manage\/knowledgebase\/wp-json\/wp\/v2\/tags?post=2665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}