{"id":1209,"date":"2021-04-07T16:08:27","date_gmt":"2021-04-07T13:08:27","guid":{"rendered":"https:\/\/www.scalahosting.com\/kb\/?p=1209"},"modified":"2023-06-20T15:37:18","modified_gmt":"2023-06-20T12:37:18","slug":"how-can-i-empty-a-mysql-database","status":"publish","type":"post","link":"https:\/\/www.scalahosting.com\/kb\/how-can-i-empty-a-mysql-database\/","title":{"rendered":"How\u200c \u200cCan\u200c \u200cI\u200c \u200cEmpty\u200c \u200ca\u200c \u200cMySQL\u200c \u200cDatabase?\u200c"},"content":{"rendered":"<p><b>What happens when a MySQL database runs out of disk space?<\/b><\/p>\n<p><span style=\"font-weight: 400;\">If you are conversant with MySQL databases, you\u2019ll notice that the MySQL will become unresponsive, and <\/span><b>the application will return Error 28.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">When this happens, you\u2019ve some options to clear up the disk space to enable MySQL to continue writing to the disk and resume operation.\u00a0<\/span><\/p>\n<p><b>You could:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Remove unnecessary files from the database.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Delete old and unwanted tables from the database, and run the \u201cOPTIMIZE TABLE\u201d SQL query command to move the freed space to the OS.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Purge the binary logs; that\u2019s if the MySQL is still responsive and you enabled the binary option in your MySQL server.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Add more space to the disk or partition.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Or you could even empty the entire database.<\/span><\/p>\n<p><b>The article guides<\/b><span style=\"font-weight: 400;\"> you through all you need to know on how to empty a MySQL database.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So, let\u2019s get started.<\/span><\/p>\n<h2><b>Method\u200c \u200c1:\u200c \u200cVia\u200c \u200cphpMyAdmin\u200c \u200c<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">You could empty<\/span><b> a MySQL database by dropping the tables, and luckily, the phpMyAdmin web interface makes this more effortless.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The phpMyAdmin is free software that helps in the administration of MySQL and MariaDB over the web. It\u2019s like a control panel that streamlines MySQL management to eliminate the need to memorize and write MySQL command codes.<\/span><\/p>\n<p><b>It helps users <\/b><b>manage:\u00a0<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Databases\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Tables<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Columns<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Relations<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Indexes<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Users<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Permissions, etc<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">\u00a0To get started with phpMyAdmin, log in to your <\/span><a href=\"https:\/\/www.scalahosting.com\/kb\/getting-started-with-spanel\/\"><span style=\"font-weight: 400;\">Spanel account<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1214\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image1-6.png\" alt=\"How\u200c \u200cCan\u200c \u200cI\u200c \u200cEmpty\u200c \u200ca\u200c \u200cMySQL\u200c \u200cDatabase?\u200c, Method\u200c \u200c1:\u200c \u200cVia\u200c \u200cphpMyAdmin\u200c \u200c\" width=\"343\" height=\"339\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image1-6.png 343w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image1-6-300x297.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">The Spanel is Scalahosting\u2019s all-in-one control panel <\/span><span style=\"font-weight: 400;\">that enables you to manage your entire hosting account without paying any additional licensing fees.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the Spanel dashboard, click on the <\/span><b>phpMyAdmin<\/b><span style=\"font-weight: 400;\"> tool under the <\/span><b>Databases<\/b><span style=\"font-weight: 400;\"> section.<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1210\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image3-6.png\" alt=\"How\u200c \u200cCan\u200c \u200cI\u200c \u200cEmpty\u200c \u200ca\u200c \u200cMySQL\u200c \u200cDatabase?\u200c, Method\u200c \u200c1:\u200c \u200cVia\u200c \u200cphpMyAdmin\u200c \u200c 2\" width=\"510\" height=\"162\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image3-6.png 510w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image3-6-300x95.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Spanel will redirect you to the phpMyAdmin web console. On the interface, click <\/span><b>Databases<\/b><span style=\"font-weight: 400;\"> on the top menu bar.<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1212\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image5-5.png\" alt=\"How\u200c \u200cCan\u200c \u200cI\u200c \u200cEmpty\u200c \u200ca\u200c \u200cMySQL\u200c \u200cDatabase?\u200c, Method\u200c \u200c1:\u200c \u200cVia\u200c \u200cphpMyAdmin\u200c \u200c 3\" width=\"893\" height=\"205\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image5-5.png 893w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image5-5-300x69.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image5-5-768x176.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">You\u2019ll see a list of your databases; click on the name of the database you intend to empty. Doing this will open the database, and you\u2019ll see all its tables.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Click on<\/span><b> Check all<\/b><span style=\"font-weight: 400;\"> to select all the tables at a go.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Or, you could opt to select the tables individually if there are specific tables you don\u2019t intend to delete.<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1215\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image2-6.png\" alt=\"How\u200c \u200cCan\u200c \u200cI\u200c \u200cEmpty\u200c \u200ca\u200c \u200cMySQL\u200c \u200cDatabase?\u200c, Method\u200c \u200c1:\u200c \u200cVia\u200c \u200cphpMyAdmin\u200c \u200c 4\" width=\"1002\" height=\"400\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image2-6.png 1002w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image2-6-300x120.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image2-6-768x307.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">After checking all the tables you want to drop, click on <\/span><b>With selected<\/b><span style=\"font-weight: 400;\"> below the tables and select <\/span><b>Drop<\/b><span style=\"font-weight: 400;\"> 0n the menu list.<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1211\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image4-6.png\" alt=\"How\u200c \u200cCan\u200c \u200cI\u200c \u200cEmpty\u200c \u200ca\u200c \u200cMySQL\u200c \u200cDatabase?\u200c, Method\u200c \u200c1:\u200c \u200cVia\u200c \u200cphpMyAdmin\u200c \u200c 5\" width=\"1073\" height=\"360\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image4-6.png 1073w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image4-6-300x101.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image4-6-1024x344.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2021\/04\/image4-6-768x258.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">This command will execute <\/span><b>the \u201cDROP TABLE\u201d SQL <\/b><span style=\"font-weight: 400;\">query to drop the selected tables at once.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Click on the <\/span><b>Go<\/b><span style=\"font-weight: 400;\"> button in the next step to confirm and finally execute the task.<\/span><\/p>\n<h2><b>Method\u200c \u200c2:\u200c \u200cVia\u200c \u200cthe\u200c \u200cCommand\u200c \u200cLine\u200c \u200c<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Unlike the phpMyAdmin that makes emptying a database pretty straightforward, using the command line to empty a MySQL database will require you to drop the database first and recreate it.\u00a0<\/span><\/p>\n<p><b>Dropping a MySQL database via the command line is irreversible.<\/b><span style=\"font-weight: 400;\"> So, ensure that you have the <\/span><i><span style=\"font-weight: 400;\">drop and <a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-create-a-database-in-mysql\/\" target=\"_blank\" rel=\"noopener\">create database<\/a><\/span><\/i><span style=\"font-weight: 400;\"> privilege assigned to your user account. If not, you\u2019d only drop the database but won\u2019t be able to recreate it.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">And when you sort these out, here\u2019<\/span><b>s how to empty a MySQL database via the command line.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Log in to your server remotely via an SSH client to connect to the database you intend to drop. Of course, make sure to enable SSH for your hosting account.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you&#8217;re a Windows computer user, you could consider installing Putty.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Enter your hostname or IP address in the <\/span><b>Host Name<\/b><span style=\"font-weight: 400;\"> field, fill the <\/span><b>Port<\/b><span style=\"font-weight: 400;\"> field and select SSH as your connection type. Click on the <\/span><b>Open<\/b><span style=\"font-weight: 400;\"> button.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you are a macOS user, you don\u2019t have to bother installing a third-party SSH client. It comes with an in-built Terminal.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When you establish<\/span><a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-enable-ssh-access\/\"><b> an SSH connection<\/b><\/a><span style=\"font-weight: 400;\"> and access the command line, run this command to log in as the MySQL root or admin user.<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">$ mysql -u root -p<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">Or you could use this command to log in to the user assigned to the database you intend to drop.<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">Mysql -uUsername -pPassword<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">Replace<\/span> <b><i>Username<\/i><\/b><b> and <\/b><b><i>Password<\/i><\/b><b> placeholder with the MySQL username and user\u2019s password<\/b><span style=\"font-weight: 400;\">, respectively.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now, run the DROP DATABASE query on the command prompt to drop the intended database.<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">mysql&gt; DROP DATABASE dbname;<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">Replace the <\/span><i><span style=\"font-weight: 400;\">dbname<\/span><\/i><span style=\"font-weight: 400;\"> placeholder with the name of the database you intend to drop.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">That\u2019s it.<\/span><\/p>\n<h2><b>Wrapping\u200c \u200cIt\u200c \u200cUp\u200c<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">We\u2019ve made emptying <\/span><b>a MySQL database elementary and intuitive.<\/b><span style=\"font-weight: 400;\"> Follow the outlined steps to run this task any time you feel like doing so.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">But always ensure you\u2019ve got the <\/span><b>\u201cdrop and create database\u201d <\/b><span style=\"font-weight: 400;\">privileges.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You could always contact the Support team if you need help. Scalahosting provides <\/span><b>free support for database issues.<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What happens when a MySQL database runs out of disk space? If you are conversant with MySQL databases, you\u2019ll notice that the MySQL will become unresponsive, and the application will return Error 28. When this happens, you\u2019ve some options to clear up the disk space to enable MySQL to continue writing to the disk and [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","_seopress_analysis_target_kw":"","footnotes":""},"categories":[34],"tags":[],"class_list":["post-1209","post","type-post","status-publish","format-standard","hentry","category-web-hosting"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/1209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/comments?post=1209"}],"version-history":[{"count":6,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/1209\/revisions"}],"predecessor-version":[{"id":5657,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/1209\/revisions\/5657"}],"wp:attachment":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media?parent=1209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/categories?post=1209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/tags?post=1209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}