{"id":2576,"date":"2023-07-13T03:18:07","date_gmt":"2022-04-27T02:42:54","guid":{"rendered":""},"modified":"2025-02-02T00:46:18","modified_gmt":"2025-02-01T23:46:18","slug":"setting-changing-and-resetting-mysql-and-mariadb-root-passwords","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/setting-changing-and-resetting-mysql-and-mariadb-root-passwords\/","title":{"rendered":"Setting, Changing and Resetting MySQL and MariaDB Root Passwords"},"content":{"rendered":"<p>\u00a0<\/p>\n<\/p>\n<p>MySQL and MariaDB are popular open-source relational database management systems used by many websites and applications. Managing the root password is critical for securing your database. This guide will walk you through the steps to set, change, and reset the root password for both MySQL and MariaDB on a Linux server. This is especially useful in environments like  or other <a href=\"https:\/\/ie.netcloud24.com\" target=\"_blank\" rel=\"follow\">Windows VPSVirtual Private Servers<\/a>.<\/p>\n<h2>Prerequisites<\/h2>\n<p>Before starting, ensure you have the following:<\/p>\n<ul>\n<li>Access to a server running MySQL or MariaDB, which could be hosted on a <a href=\"https:\/\/ie.netcloud24.com\" target=\"_blank\" rel=\"follow\">UK Windows VPS<\/a>, <a href=\"https:\/\/ie.netcloud24.com\" target=\"_blank\" rel=\"follow\">VPS Windows VPS Servers<\/a>, or other hosting environment.<\/li>\n<li>Root or sudo privileges on your server.<\/li>\n<\/ul>\n<h2>Step 1: Setting the MySQL\/MariaDB Root Password<\/h2>\n<p>If you are setting up MySQL or MariaDB for the first time, you will need to set the root password. You can do this during the initial installation or later. If you have not set the password yet, follow these steps:<\/p>\n<pre><code>sudo mysql_secure_installation<\/code><\/pre>\n<p>During the <code>mysql_secure_installation<\/code> process, you will be prompted to set the root password. Follow the prompts to create a secure password. Once completed, your root password will be set.<\/p>\n<h2>Step 2: Changing the MySQL\/MariaDB Root Password<\/h2>\n<p>If you already have a root password but want to change it, you can do so by logging into the MySQL\/MariaDB shell with your current root credentials:<\/p>\n<pre><code>sudo mysql -u root -p<\/code><\/pre>\n<p>Once logged in, you can change the root password by executing the following command:<\/p>\n<pre><code>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';<\/code><\/pre>\n<p>Make sure to replace <code>new_password<\/code> with your desired password. Then, flush the privileges to apply the changes:<\/p>\n<pre><code>FLUSH PRIVILEGES;<\/code><\/pre>\n<p>Finally, exit the MySQL shell:<\/p>\n<pre><code>EXIT;<\/code><\/pre>\n<h2>Step 3: Resetting the MySQL\/MariaDB Root Password<\/h2>\n<p>If you have forgotten your MySQL or MariaDB root password, you can reset it by following these steps:<\/p>\n<h3>Step 3.1: Stop the MySQL\/MariaDB Service<\/h3>\n<p>First, stop the MySQL\/MariaDB service to start the server in a safe mode:<\/p>\n<pre><code>sudo systemctl stop mysql  # For MySQL\r\nsudo systemctl stop mariadb  # For MariaDB<\/code><\/pre>\n<h3>Step 3.2: Start MySQL\/MariaDB in Safe Mode<\/h3>\n<p>Next, start the server without password validation:<\/p>\n<pre><code>sudo mysqld_safe --skip-grant-tables &amp;<\/code><\/pre>\n<p>This will start the MySQL\/MariaDB server without loading the grant tables, allowing you to log in without a password.<\/p>\n<h3>Step 3.3: Log in and Reset the Root Password<\/h3>\n<p>Once the server is running in safe mode, log in as root without a password:<\/p>\n<pre><code>mysql -u root<\/code><\/pre>\n<p>Then, reset the root password using the following command:<\/p>\n<pre><code>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';<\/code><\/pre>\n<p>Afterward, flush the privileges and exit the MySQL shell:<\/p>\n<pre><code>FLUSH PRIVILEGES;\r\nEXIT;<\/code><\/pre>\n<h3>Step 3.4: Restart MySQL\/MariaDB Service<\/h3>\n<p>Finally, stop the safe mode server and restart the MySQL\/MariaDB service normally:<\/p>\n<pre><code>sudo systemctl stop mysql  # For MySQL\r\nsudo systemctl stop mariadb  # For MariaDB\r\nsudo systemctl start mysql  # For MySQL\r\nsudo systemctl start mariadb  # For MariaDB<\/code><\/pre>\n<h2>Step 4: Verifying the New Root Password<\/h2>\n<p>To verify that the new root password works, log in again using the updated password:<\/p>\n<pre><code>mysql -u root -p<\/code><\/pre>\n<p>Enter your new password when prompted, and you should be logged in successfully.<\/p>\n<h2>Conclusion<\/h2>\n<p>By following these steps, you can easily set, change, or reset the MySQL or MariaDB root password. Proper management of your root password ensures the security of your databases, which is crucial for your server environment, whether hosted on a , <a href=\"https:\/\/ie.netcloud24.com\" target=\"_blank\" rel=\"follow\">Windows VPS<\/a>, or other platforms.<\/p>\n<footer>\n<p>For more information on VPS hosting solutions, visit . They offer various <a href=\"https:\/\/ie.netcloud24.com\" target=\"_blank\" rel=\"follow\">Windows VPSVirtual Private Servers<\/a> and <a href=\"https:\/\/ie.netcloud24.com\" target=\"_blank\" rel=\"follow\">Windows VPS Hosting UK<\/a> solutions tailored to your needs.<\/p>\n<\/footer>\n<div class=\"post-author-box\" style=\"border-top:1px solid #ddd;margin-top:20px;padding-top:15px;\">\n<p><strong>Author:<\/strong> \u0141ukasz Bodziony<\/p>\n<p><strong>Website:<\/strong> <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a><\/p>\n<p><em>\u0141ukasz Bodziony is the CEO and founder of <a href=\"https:\/\/netcloud24.com\" target=\"_blank\" rel=\"dofollow\">NETCLOUD24<\/a>, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance <strong>Windows VPS<\/strong> and <strong>Remote Desktop Services (RDS)<\/strong> solutions to clients across Europe, North America, and beyond.<\/em><\/p>\n<p><em>His expertise covers a wide range of technologies, including <strong>Microsoft Azure<\/strong>, <strong>Proxmox VE<\/strong>, <strong>Amazon Web Services (AWS)<\/strong>, and numerous other virtualization and cloud platforms.<\/em><\/p>\n<p><em>Beyond running his hosting business, \u0141ukasz also provides <strong>professional paid server configuration and optimization services<\/strong> for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.<\/em><\/p>\n<p><em>If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a>.<\/em><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 MySQL and MariaDB are popular open-source relational database management systems used by many websites and applications. Managing the root password is critical for securing your database. This\u2026<\/p>\n","protected":false},"author":1,"featured_media":3421,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[14,12,11,23,20,21,22,17,7,8,6,10,18,19,15,24,16,5,13,9],"class_list":["post-2576","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-cheapvps","tag-cloudvps","tag-hostingvps","tag-rds","tag-rdscal","tag-remotedesktop","tag-remotedesktopvps","tag-servervps","tag-ukvps","tag-virtualserver","tag-vpshosting","tag-vpsserver","tag-vpssolutions","tag-vpswindows","tag-vpswithwindows","tag-windowsrds","tag-windowsserver","tag-windowsvps","tag-windowsvpshosting","tag-windowsvpsuk"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=2576"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2576\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media\/3421"}],"wp:attachment":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=2576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=2576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=2576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}