{"id":3092,"date":"2022-02-03T16:03:15","date_gmt":"2022-02-03T14:03:15","guid":{"rendered":"https:\/\/www.scalahosting.com\/kb\/?p=3092"},"modified":"2023-03-13T13:41:18","modified_gmt":"2023-03-13T11:41:18","slug":"what-is-a-database-host-in-wordpress","status":"publish","type":"post","link":"https:\/\/www.scalahosting.com\/kb\/what-is-a-database-host-in-wordpress\/","title":{"rendered":"What Is a Database Host in WordPress?"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Everybody knows that the database is an integral part of any WordPress website. However, many people don&#8217;t really understand how it works and what it does. Site owners are also a bit baffled when WP asks them to set <\/span><b>a database host<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s clear up some of the confusion, starting with the basics.<\/span><b><\/b><\/p>\n<h2><b>What Is a WordPress Database?<\/b><b><\/b><\/h2>\n<p><span style=\"font-weight: 400;\">The database is where your website&#8217;s data is stored. Thanks to it, instead of a<\/span><b> collection of static HTML pages with images and text<\/b><span style=\"font-weight: 400;\">, you can have an interactive website where users can sign up, leave comments, generate and manage data, search through and filter content, and a lot more.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the database, you have anything from the <\/span><b>posts<\/b><span style=\"font-weight: 400;\"> and <\/span><b>pages<\/b><span style=\"font-weight: 400;\"> you write, through <\/span><b>users&#8217; personal data<\/b><span style=\"font-weight: 400;\">, to <\/span><b>WP&#8217;s core configuration and settings<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The information in the database <\/span><b>shouldn&#8217;t be freely accessible<\/b><span style=\"font-weight: 400;\">. That&#8217;s why, in addition to a database, you also need to create <\/span><b>a user account<\/b><span style=\"font-weight: 400;\">. It has <\/span><b>a username, a password, and a set of permissions<\/b><span style=\"font-weight: 400;\"> governing what it&#8217;s allowed to do with the data.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">WordPress uses this user account to retrieve the information and serve it to the site&#8217;s visitors. Users of ScalaHosting&#8217;s SPanel VPS services can view and <\/span><a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-create-or-delete-a-mysql-database-or-user\/\"><b>manage MySQL user accounts and databases<\/b><\/a><span style=\"font-weight: 400;\"> via the <\/span><b>MySQL Databases<\/b><span style=\"font-weight: 400;\"> tool in <\/span><b>SPanel&#8217;s User Interface.<\/b><\/p>\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-3093\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/02\/image2-969x1024.png\" alt=\"What Is a Database Host in WordPress?, What Is a WordPress Database?\" width=\"969\" height=\"1024\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/02\/image2-969x1024.png 969w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/02\/image2-284x300.png 284w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/02\/image2-768x811.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/02\/image2-1454x1536.png 1454w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/02\/image2.png 1892w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<h2><b>What Is a Database Table?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">WordPress works with <\/span><b>MySQL databases<\/b><span style=\"font-weight: 400;\"> which organize the information in tables. During the initial installation, WP automatically creates the required tables for <\/span><b>users, posts, comments, options, etc<\/b><span style=\"font-weight: 400;\">., with more being added at later stages (e.g., <\/span><i><span style=\"font-weight: 400;\">when you install plugins<\/span><\/i><span style=\"font-weight: 400;\">).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can view all tables through the <\/span><b>phpMyAdmin database management tool<\/b><span style=\"font-weight: 400;\"> inside your web hosting control panel.<\/span><\/p>\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-3094\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/02\/image1-1024x522.png\" alt=\"What Is a Database Host in WordPress?, What Is a Database Table?\" width=\"1024\" height=\"522\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/02\/image1-1024x522.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/02\/image1-300x153.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/02\/image1-768x392.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/02\/image1-1536x783.png 1536w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/02\/image1.png 1920w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<p><span style=\"font-weight: 400;\">Tables allow for <\/span><b>a tidier database and a quicker delivery of the requested information<\/b><span style=\"font-weight: 400;\">.<\/span><b><\/b><\/p>\n<h2><b>What Is an SQL Query?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">WordPress and the database communicate through <\/span><b>SQL queries<\/b><span style=\"font-weight: 400;\">. In simple terms, whenever WP needs to display a piece of information, it sends an SQL query. The <\/span><b>MySQL server processes it<\/b><span style=\"font-weight: 400;\"> and responds with the correct data.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">All manner of events may trigger an<\/span><b> SQL query<\/b><span style=\"font-weight: 400;\">. It could be a user clicking on a button, you filtering comments in the <\/span><a href=\"https:\/\/www.scalahosting.com\/blog\/navigating-your-wordpress-dashboard\/\"><b>WP dashboard<\/b><\/a><span style=\"font-weight: 400;\">, or a plugin trying to alter some settings.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Traffic volumes directly affect the number of queries your server needs to process, but they&#8217;re far from the only factor. <\/span><b>Complex WP plugins<\/b><span style=\"font-weight: 400;\"> can also generate quite a few database queries and significantly affect your hardware resource usage.<\/span><b><\/b><\/p>\n<h2><b>What Is a Database Host?<\/b><b><\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Many people understand the roles of the <\/span><i><span style=\"font-weight: 400;\">database, the MySQL user, and the SQL queries<\/span><\/i><span style=\"font-weight: 400;\">. However, they still get confused when, for example, they&#8217;re <\/span><a href=\"https:\/\/www.scalahosting.com\/blog\/how-to-install-wordpress\/\"><b>setting up WordPress manually<\/b><\/a><span style=\"font-weight: 400;\">, and the installation wizard asks them for <\/span><b>the database host<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">By default, the wizard sets it to &#8220;<\/span><b>localhost<\/b><span style=\"font-weight: 400;\">,&#8221; and a quick Google search reveals leaving it like this will work in most cases. However, the search engine results rarely explain <\/span><i><span style=\"font-weight: 400;\">what the database host actually is.<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">In simple terms, it&#8217;s <\/span><b>the server hosting the database<\/b><span style=\"font-weight: 400;\">. Most website owners host the site and the database on the same server, so leaving &#8220;localhost&#8221; in the DB host field usually works.<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">But what if you want to put the database on another machine? Is it possible to do it? Yes, it is. However, there are certain preparations you need to take care of first.<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">You need to make sure MySQL on the database host is <\/span><b>configured to receive connections from your web hosting server<\/b><span style=\"font-weight: 400;\">. If you don&#8217;t have root access to the database host, you might need some assistance with this because it involves editing MySQL&#8217;s main configuration file &#8211; <\/span><i><span style=\"font-weight: 400;\">\/etc\/mysql\/my.cnf<\/span><\/i><span style=\"font-weight: 400;\">. You need to find the <\/span><i><span style=\"font-weight: 400;\">bind-address<\/span><\/i> <span style=\"font-weight: 400;\">parameter and set it to the IP of your web hosting server. A restart of the MySQL service saves the changes.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Next, you&#8217;ll have to create the MySQL user account WP will use to connect to the database. Depending on the database host, you&#8217;ll need to do that either through the control panel or via the command-line interface. You need to make sure you set <\/span><b>the new user account&#8217;s hostname to your web hosting server&#8217;s IP<\/b><span style=\"font-weight: 400;\"> (i.e.,<\/span> <i><span style=\"font-weight: 400;\">user@xx.xx.xx.xx<\/span><\/i><span style=\"font-weight: 400;\"> instead of<\/span><i><span style=\"font-weight: 400;\"> user@localhost<\/span><\/i><span style=\"font-weight: 400;\">).<\/span><i><span style=\"font-weight: 400;\">\u00a0<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">Pay attention to <\/span><b>the permissions<\/b><span style=\"font-weight: 400;\"> the MySQL user account gets. WordPress needs the<\/span> <b><i>select<\/i><\/b><b>, <\/b><b><i>delete<\/i><\/b><b>, <\/b><b><i>insert<\/i><\/b><b>, and <\/b><b><i>update<\/i><\/b><b> privileges<\/b><span style=\"font-weight: 400;\"> to work correctly, and security best practices dictate that these are the privileges you&#8217;ll need to give the new user. However, if you&#8217;re configuring a fresh installation, you&#8217;ll need to grant it full permissions, at least until WP is fully set up and ready to go.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The only thing left is to <\/span><b>configure WordPress to work with the remote database host<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you&#8217;re installing WordPress manually, you can do that from the installation wizard. You&#8217;ll need to enter the<\/span><b> database name<\/b><span style=\"font-weight: 400;\">, the <\/span><b>MySQL account&#8217;s login credentials<\/b><span style=\"font-weight: 400;\">, and the <\/span><b>database host&#8217;s IP address<\/b><span style=\"font-weight: 400;\">.<\/span> <span style=\"font-weight: 400;\">WP should have no problems connecting to the database if everything is configured correctly.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you&#8217;re using an automatic installer or re-configuring an existing WordPress installation, you&#8217;ll need to edit the <\/span><b>wp-config.php file<\/b><span style=\"font-weight: 400;\">. The parameters you need to look for are:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">DB_NAME<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">DB_USER<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">DB_PASSWORD<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">DB_HOST<\/span><\/li>\n<\/ul>\n<h2><b>Potential Problems With Using a Different Host for Your Database<\/b><b><\/b><\/h2>\n<p><span style=\"font-weight: 400;\">The point of hosting your site&#8217;s database on a different server is to lower the load on the primary host and <\/span><a href=\"https:\/\/www.scalahosting.com\/blog\/how-to-speed-up-a-wordpress-website\/\"><b>improve the site&#8217;s performance<\/b><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">However, many people are left surprised when they move their database to a different machine, and instead of reduced loading times, they witness <\/span><b>a significant drop in performance<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Hiring a separate database host can backfire because of latency. If the database and the <\/span><a href=\"https:\/\/www.scalahosting.com\/web-hosting-for-small-business.html\"><b>web hosting server<\/b><\/a><span style=\"font-weight: 400;\"> are located <\/span><b>in different data centers<\/b><span style=\"font-weight: 400;\">, the data will need to travel a long way before WordPress can serve it to the site&#8217;s visitors.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Because of all this, experts advise that if you&#8217;re going to use a separate database host, you&#8217;re better off having <\/span><b>both machines located on the same network<\/b><span style=\"font-weight: 400;\">. The data will be transferred more quickly, and the site&#8217;s visitors will instantly feel the reduced load on the main hosting server.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If this is the setup you&#8217;re going for, you need to use the machines&#8217; <\/span><b>local rather than public IPs<\/b><span style=\"font-weight: 400;\"> when setting up the <\/span><b>database host and configuring WordPress.<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Everybody knows that the database is an integral part of any WordPress website. However, many people don&#8217;t really understand how it works and what it does. Site owners are also a bit baffled when WP asks them to set a database host. Let&#8217;s clear up some of the confusion, starting with the basics. What Is [&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":"","footnotes":""},"categories":[34],"tags":[],"class_list":["post-3092","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\/3092","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=3092"}],"version-history":[{"count":2,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/3092\/revisions"}],"predecessor-version":[{"id":5454,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/3092\/revisions\/5454"}],"wp:attachment":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media?parent=3092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/categories?post=3092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/tags?post=3092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}