
{"id":25990,"date":"2025-10-03T09:29:51","date_gmt":"2025-10-03T07:29:51","guid":{"rendered":"https:\/\/contabo.com\/blog\/?p=25990"},"modified":"2026-01-16T10:59:49","modified_gmt":"2026-01-16T09:59:49","slug":"how-to-install-mysql-and-crate-databases","status":"publish","type":"post","link":"https:\/\/contabo.com\/blog\/how-to-install-mysql-and-crate-databases\/","title":{"rendered":"How to Install MySQL and Create Databases"},"content":{"rendered":"\n<p>Installing and managing MySQL doesn\u2019t have to be complicated. In just a few minutes, you can set up MySQL on your Linux server, create your first database, and even automate backups &#8211; all while ensuring your data stays safe and organized.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-mysql\">What Is MySQL\u00a0<\/h2>\n\n\n\n<p>MySQL is a <strong>relational database management system (RDBMS)<\/strong> that uses <strong>Structured Query Language (SQL)<\/strong> to organize and manage data efficiently. It\u2019s one of the most popular open-source database systems worldwide, widely used in web development, e-commerce, and business applications.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-common-use-cases\">Common Use Cases\u00a0<\/h2>\n\n\n\n<p>MySQL is a reliable choice for various applications, including:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Web applications:<\/strong> Managing user authentication and storing website content (e.g., WordPress, Drupal).&nbsp;<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>E-commerce platforms:<\/strong> Handling product catalogs, customer orders, and transactions (e.g., Magento, WooCommerce).&nbsp;<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Data analytics:<\/strong> Storing and analyzing structured data for business insights.&nbsp;<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Business tools:<\/strong> Tracking customer records, finances, and inventory.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p>If you\u2019ve ever logged into a website or completed an online purchase, there\u2019s a good chance MySQL was running behind the scenes.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-installing-mysql-on-linux-debian-based-systems\">Installing MySQL on Linux (Debian-Based Systems)\u00a0<\/h2>\n\n\n\n<p>Installing MySQL on Ubuntu or Debian-based systems is simple and quick. Follow these steps:&nbsp;<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Update your packages and install MySQL:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get update &amp;&amp; sudo apt-get install mysql-server -y&nbsp;<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Secure the installation:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql_secure_installation&nbsp;<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Check the MySQL service status:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status mysql&nbsp;<\/code><\/pre>\n\n\n\n<p>If the service is inactive, start it using:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl start mysql &nbsp;<\/code><\/pre>\n\n\n\n<p>At this point, MySQL should be running on your system.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-creating-a-mysql-database-and-table\">Creating a MySQL Database and Table\u00a0<\/h2>\n\n\n\n<p>Once MySQL is installed, you can create your first database and table.&nbsp;<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Log in to MySQL:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p&nbsp;<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Create a new database:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE my_database;&nbsp;<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Switch to that database and create a table:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>USE my_database;&nbsp;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE users (&nbsp;\n&nbsp;&nbsp;&nbsp; id INT AUTO_INCREMENT PRIMARY KEY,&nbsp;\n&nbsp;&nbsp;&nbsp; name VARCHAR(100),&nbsp;\n&nbsp;&nbsp;&nbsp; email VARCHAR(100) UNIQUE&nbsp;\n);&nbsp;<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Insert data into the table:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com');&nbsp;<\/code><\/pre>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li><strong>Retrieve the data:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM users;&nbsp;<\/code><\/pre>\n\n\n\n<p>Congratulations &#8211; you\u2019ve just created and populated your first MySQL database.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-managing-users-and-permissions\">Managing Users and Permissions\u00a0<\/h2>\n\n\n\n<p>For better security, avoid using the root account for daily database tasks. Instead, create a dedicated user.&nbsp;<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Create a new user:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'secure_password';&nbsp;<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Grant privileges:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>GRANT ALL PRIVILEGES ON my_database.* TO 'new_user'@'localhost'; FLUSH PRIVILEGES;&nbsp;<\/code><\/pre>\n\n\n\n<p>This new user now has full access to my_database without exposing the root credentials.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-backing-up-and-restoring-databases\">Backing Up and Restoring Databases\u00a0<\/h2>\n\n\n\n<p>Regular backups are essential to prevent data loss.&nbsp;<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Create a backup:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump -u root -p my_database &gt; backup.sql&nbsp;<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Restore a backup:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p my_database &lt; backup.sql&nbsp;<\/code><\/pre>\n\n\n\n<p>This command restores the data from the backup file.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-automating-backups\">Automating Backups\u00a0<\/h2>\n\n\n\n<p>To simplify maintenance, you can automate MySQL backups with a simple script and a scheduled task.&nbsp;<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Create a shell script:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>nano backup.sh&nbsp;<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Add the following content:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash&nbsp;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump -u root -p&#91;password] my_database &gt; \/path\/to\/backup.sql&nbsp;<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Schedule daily backups using Cron:<\/strong>&nbsp;<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>crontab -e&nbsp;<\/code><\/pre>\n\n\n\n<p>Then add this line:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 3 * * * \/path\/to\/backup.sh&nbsp;<\/code><\/pre>\n\n\n\n<p>Your server will now automatically back up your database every day at 3 a.m.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-watch-our-youtube-video-on-mysql\">Watch Our YouTube Video on MySQL\u00a0<\/h2>\n\n\n\n<p>You are more of a visual learner and prefer a visual walk through? We have a YouTube video for you, going through all the steps discussed in this article.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"ast-oembed-container \" style=\"height: 100%;\"><iframe loading=\"lazy\" title=\"How to install MySQL and create databases\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/xB0aIU_MKIM?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/div>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion\u00a0<\/h2>\n\n\n\n<p>You\u2019ve now installed MySQL, created and managed databases, configured user permissions, and set up automated backups. With these steps, your server is ready to handle data efficiently and securely.&nbsp;<\/p>\n\n\n\n<p>For more tutorials and hosting tips, explore other guides from <strong>Contabo<\/strong> &#8211; and keep your systems optimized and protected for every project.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Installing and managing MySQL doesn\u2019t have to be complicated. In just a few minutes, you can set up MySQL on your Linux server, create your first database, and even automate backups &#8211; all while ensuring your data stays safe and organized.&nbsp; What Is MySQL\u00a0 MySQL is a relational database management system (RDBMS) that uses Structured [&hellip;]<\/p>\n","protected":false},"author":77,"featured_media":25994,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[],"ppma_author":[3116],"class_list":["post-25990","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"uagb_featured_image_src":{"full":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2025\/11\/How-to-Install-mySQL.png",1200,630,false],"thumbnail":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2025\/11\/How-to-Install-mySQL-150x150.png",150,150,true],"medium":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2025\/11\/How-to-Install-mySQL-600x315.png",600,315,true],"medium_large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2025\/11\/How-to-Install-mySQL-768x403.png",768,403,true],"large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2025\/11\/How-to-Install-mySQL.png",1200,630,false],"1536x1536":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2025\/11\/How-to-Install-mySQL.png",1200,630,false],"2048x2048":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2025\/11\/How-to-Install-mySQL.png",1200,630,false]},"uagb_author_info":{"display_name":"Anika Kopte","author_link":"https:\/\/contabo.com\/blog\/author\/anika\/"},"uagb_comment_info":0,"uagb_excerpt":"Installing and managing MySQL doesn\u2019t have to be complicated. In just a few minutes, you can set up MySQL on your Linux server, create your first database, and even automate backups &#8211; all while ensuring your data stays safe and organized.&nbsp; What Is MySQL\u00a0 MySQL is a relational database management system (RDBMS) that uses Structured&hellip;","authors":[{"term_id":3116,"user_id":77,"is_guest":0,"slug":"anika","display_name":"Anika Kopte","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/1c425caa652c679ae47e3f85a48de4e19f09d37bcb5593ba88a7aa4a08bb1d81?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/25990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/comments?post=25990"}],"version-history":[{"count":4,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/25990\/revisions"}],"predecessor-version":[{"id":27366,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/25990\/revisions\/27366"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media\/25994"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=25990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=25990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=25990"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=25990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}