{"id":1620,"date":"2012-01-10T06:50:45","date_gmt":"2012-01-09T22:50:45","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=1620"},"modified":"2023-04-28T09:49:59","modified_gmt":"2023-04-28T09:49:59","slug":"how-to-set-mysql-root-password-on-centos-6-2","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-set-mysql-root-password-on-centos-6-2\/","title":{"rendered":"How to Set MySQL root Password on CentOS 6.2"},"content":{"rendered":"<p>MySQL is a popular open-source relational database management system. By default, the root user account in MySQL is not password protected, which can pose a security risk.<\/p>\n<p>In this guide, we will show you how to set a root password for MySQL on CentOS 6.2.<\/p>\n<h2>Step 1: Log in to MySQL as the Root User<\/h2>\n<p>The first step is to log in to MySQL as the root user. Open your terminal and type the following command:<\/p>\n<pre>mysql -u root<\/pre>\n<p>This command will log you in to MySQL as the root user without a password.<\/p>\n<h2>Step 2: Set the Root Password<\/h2>\n<p>Once you are logged in, you need to set the root password. Run the following command:<\/p>\n<pre>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');<\/pre>\n<p>Replace &#8216;yourpassword&#8217; with your desired password. Make sure your password is strong and secure.<\/p>\n<h2>Step 3: Flush the Privileges<\/h2>\n<p>After setting the root password, you need to flush the privileges to apply the changes. Run the following command:<\/p>\n<pre>FLUSH PRIVILEGES;<\/pre>\n<h2>Step 4: Test the New Root Password<\/h2>\n<p>Finally, you need to test the new root password to make sure it is working. Log out of MySQL by running the following command:<\/p>\n<pre>exit;<\/pre>\n<p>Now, log in to MySQL again using the new password:<\/p>\n<pre>mysql -u root -p<\/pre>\n<p>You will be prompted to enter the new password. Enter it and hit Enter. If the password is correct, you will be logged in to MySQL.<\/p>\n<pre class=\"code\">\r\n[root@centos6 ~]# mysql -u root -p\r\nEnter password:\r\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\r\nYour MySQL connection id is 150\r\nServer version: 5.1.52 Source distribution\r\n\r\nCopyright (c) 2000, 2010, Oracle and\/or its affiliates. All rights reserved.\r\nThis software comes with ABSOLUTELY NO WARRANTY. This is free software,\r\nand you are welcome to modify and redistribute it under the GPL v2 license\r\n\r\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\r\n\r\nmysql> select user,host,password from mysql.user;\r\n+---------------+-----------+-------------------------------------------+\r\n| user          | host      | password                                  |\r\n+---------------+-----------+-------------------------------------------+\r\n| root          | localhost |                                           |\r\n| root          | centos6.2 |                                           |\r\n| root          | 127.0.0.1 |                                           |\r\n|               | localhost |                                           |\r\n|               | centos6.2 |                                           |\r\n+---------------+-----------+-------------------------------------------+\r\n7 rows in set (0.00 sec)\r\n\r\nmysql> set password for root@'localhost'=password('password');\r\nQuery OK, 0 rows affected (0.00 sec)\r\n\r\nmysql> set password for root@'127.0.0.1'=password('password');\r\nQuery OK, 0 rows affected (0.00 sec)\r\n\r\nmysql> set password for root@'centos6.2'=password('password');\r\nQuery OK, 0 rows affected (0.00 sec)\r\n\r\n\r\nmysql> select user,host,password from mysql.user;\r\n+---------------+-----------+-------------------------------------------+\r\n| user          | host      | password                                  |\r\n+---------------+-----------+-------------------------------------------+\r\n| root          | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |\r\n| root          | centos6.2 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |\r\n| root          | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |\r\n|               | localhost |                                           |\r\n|               | centos6.2 |                                           |\r\n+---------------+-----------+-------------------------------------------+\r\n7 rows in set (0.00 sec)\r\n\r\nmysql> select user,host,password from mysql.user;\r\n+---------------+-----------+-------------------------------------------+\r\n| user          | host      | password                                  |\r\n+---------------+-----------+-------------------------------------------+\r\n| root          | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |\r\n| root          | centos6.2 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |\r\n| root          | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |\r\n|               | localhost |                                           |\r\n|               | centos6.2 |                                           |\r\n+---------------+-----------+-------------------------------------------+\r\n5 rows in set (0.00 sec)\r\n\r\nmysql> exit\r\nBye\r\n<\/pre>\n<h2>Commands Mentioned:<\/h2>\n<ul>\n<li><span class=\"fw-bold\">mysql -u root<\/span> &#8211; Log in to MySQL as the root user<\/li>\n<li><span class=\"fw-bold\">SET PASSWORD FOR &#8216;root&#8217;@&#8217;localhost&#8217; = PASSWORD(&#8216;yourpassword&#8217;);<\/span> &#8211; Set the root password<\/li>\n<li><span class=\"fw-bold\">FLUSH PRIVILEGES;<\/span> &#8211; Flush the privileges<\/li>\n<li><span class=\"fw-bold\">exit;<\/span> &#8211; Log out of MySQL<\/li>\n<li><span class=\"fw-bold\">mysql -u root -p<\/span> &#8211; Log in to MySQL with a password<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>In this guide, we have shown you how to set a root password for MySQL on CentOS 6.2. By following these steps, you can protect your MySQL installation from unauthorized access. We recommend that you use a strong and secure password and keep it safe.<\/p>\n<p>If you have any comments or suggestions for improvements, please feel free to share them below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL is a popular open-source relational database management system. By default, the root user account in MySQL is not password protected, which can pose a security risk. In this guide,&#8230;<\/p>\n","protected":false},"author":6,"featured_media":343,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1008],"tags":[1253,1536,1585,1720],"class_list":["post-1620","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","tag-centos-6-2","tag-linux","tag-mysql","tag-root"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/1620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=1620"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/1620\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/343"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=1620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=1620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=1620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}