{"id":4701,"date":"2013-05-26T01:29:23","date_gmt":"2013-05-25T17:29:23","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=4701"},"modified":"2023-06-28T11:46:21","modified_gmt":"2023-06-28T11:46:21","slug":"how-to-install-and-securing-mysql-on-centos-6-4","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-install-and-securing-mysql-on-centos-6-4\/","title":{"rendered":"How to Install and Securing MySQL on CentOS 6.4 VPS"},"content":{"rendered":"<p>MySQL is one of the most widely used databases on the internet, particularly for content management and blogging sites. It stores and retrieves data for blogs, websites, and applications.<\/p>\n<p>This guide will walk you through the process of installing and securing MySQL on a CentOS 6.4 virtual private server (VPS) or a dedicated MySQL database server. For more information on MySQL, you can visit their website at <a href=\"https:\/\/www.mysql.com\" target=\"_blank\" rel=\"nofollow noopener\">www.mysql.com<\/a>.<\/p>\n<h2>Installing MySQL Database Server<\/h2>\n<p>To install MySQL Database Server, you will use the yum command. The command to use is:<\/p>\n<pre>\r\nyum install mysql mysql-server -y\r\n<\/pre>\n<p>This command will install the MySQL server and client on your CentOS system. The &#8220;-y&#8221; option tells yum to automatically answer &#8220;yes&#8221; to any prompts, allowing the installation to proceed without your intervention.<\/p>\n<p>Example:<\/p>\n<pre>\r\n[root@centos64 ~]# yum install mysql mysql-server -y\r\nLoaded plugins: fastestmirror\r\nLoading mirror speeds from cached hostfile\r\n * base: mirror.upsi.edu.my\r\n * epel: kartolo.sby.datautama.net.id\r\n * extras: mirror.upsi.edu.my\r\n * updates: mirror.upsi.edu.my\r\nSetting up Install Process\r\nResolving Dependencies\r\n--> Running transaction check\r\n---> Package mysql.x86_64 0:5.1.69-1.el6_4 will be installed\r\n--> Processing Dependency: mysql-libs = 5.1.69-1.el6_4 for package: mysql-5.1.69-1.el6_4.x86_64\r\n---> Package mysql-server.x86_64 0:5.1.69-1.el6_4 will be installed\r\n--> Processing Dependency: perl-DBI for package: mysql-server-5.1.69-1.el6_4.x86_64\r\n--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.69-1.el6_4.x86_64\r\n--> Processing Dependency: perl(DBI) for package: mysql-server-5.1.69-1.el6_4.x86_64\r\n--> Running transaction check\r\n---> Package mysql-libs.x86_64 0:5.1.67-1.el6_3 will be updated\r\n---> Package mysql-libs.x86_64 0:5.1.69-1.el6_4 will be an update\r\n---> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed\r\n---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed\r\n--> Finished Dependency Resolution\r\n\r\nDependencies Resolved\r\n\r\n====================================================================================================\r\n Package                    Arch               Version                    Repository           Size\r\n====================================================================================================\r\nInstalling:\r\n mysql                      x86_64             5.1.69-1.el6_4             updates             907 k\r\n mysql-server               x86_64             5.1.69-1.el6_4             updates             8.7 M\r\nInstalling for dependencies:\r\n perl-DBD-MySQL             x86_64             4.013-3.el6                base                134 k\r\n perl-DBI                   x86_64             1.609-4.el6                base                705 k\r\nUpdating for dependencies:\r\n mysql-libs                 x86_64             5.1.69-1.el6_4             updates             1.2 M\r\n\r\nTransaction Summary\r\n====================================================================================================\r\nInstall       4 Package(s)\r\nUpgrade       1 Package(s)\r\n\r\nTotal download size: 12 M\r\nDownloading Packages:\r\n(1\/5): mysql-5.1.69-1.el6_4.x86_64.rpm                                       | 907 kB     00:07\r\n(2\/5): mysql-libs-5.1.69-1.el6_4.x86_64.rpm                                  | 1.2 MB     00:12\r\n(3\/5): mysql-server-5.1.69-1.el6_4.x86_64.rpm                                | 8.7 MB     01:30\r\n(4\/5): perl-DBD-MySQL-4.013-3.el6.x86_64.rpm                                 | 134 kB     00:00\r\n(5\/5): perl-DBI-1.609-4.el6.x86_64.rpm                                       | 705 kB     00:06\r\n----------------------------------------------------------------------------------------------------\r\nTotal                                                               101 kB\/s |  12 MB     01:57\r\nRunning rpm_check_debug\r\nRunning Transaction Test\r\nTransaction Test Succeeded\r\nRunning Transaction\r\n  Updating   : mysql-libs-5.1.69-1.el6_4.x86_64                                                 1\/6\r\n  Installing : perl-DBI-1.609-4.el6.x86_64                                                      2\/6\r\n  Installing : perl-DBD-MySQL-4.013-3.el6.x86_64                                                3\/6\r\n  Installing : mysql-5.1.69-1.el6_4.x86_64                                                      4\/6\r\n  Installing : mysql-server-5.1.69-1.el6_4.x86_64                                               5\/6\r\n  Cleanup    : mysql-libs-5.1.67-1.el6_3.x86_64                                                 6\/6\r\n  Verifying  : mysql-libs-5.1.69-1.el6_4.x86_64                                                 1\/6\r\n  Verifying  : perl-DBD-MySQL-4.013-3.el6.x86_64                                                2\/6\r\n  Verifying  : perl-DBI-1.609-4.el6.x86_64                                                      3\/6\r\n  Verifying  : mysql-server-5.1.69-1.el6_4.x86_64                                               4\/6\r\n  Verifying  : mysql-5.1.69-1.el6_4.x86_64                                                      5\/6\r\n  Verifying  : mysql-libs-5.1.67-1.el6_3.x86_64                                                 6\/6\r\n\r\nInstalled:\r\n  mysql.x86_64 0:5.1.69-1.el6_4                 mysql-server.x86_64 0:5.1.69-1.el6_4\r\n\r\nDependency Installed:\r\n  perl-DBD-MySQL.x86_64 0:4.013-3.el6                 perl-DBI.x86_64 0:1.609-4.el6\r\n\r\nDependency Updated:\r\n  mysql-libs.x86_64 0:5.1.69-1.el6_4\r\n\r\nComplete!\r\n<\/pre>\n<h2>Starting MySQL Database Server<\/h2>\n<p>Once the installation is complete, you will want to ensure that the MySQL daemon starts at boot. You can do this by using the chkconfig command:<\/p>\n<pre>\r\nchkconfig mysqld on\r\n<\/pre>\n<p>After setting the MySQL daemon to start at boot, you can start the MySQL Database Server with the following command:<\/p>\n<pre>\r\nservice mysqld start\r\n<\/pre>\n<p>Example:<\/p>\n<pre>\r\n[root@centos64 ~]# chkconfig mysqld on\r\n[root@centos64 ~]# service mysqld start\r\nInitializing MySQL database:  Installing MySQL system tables...\r\nOK\r\nFilling help tables...\r\nOK\r\n\r\nTo start mysqld at boot time you have to copy\r\nsupport-files\/mysql.server to the right place for your system\r\n\r\nPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !\r\nTo do so, start the server, then issue the following commands:\r\n\r\n\/usr\/bin\/mysqladmin -u root password 'new-password'\r\n\/usr\/bin\/mysqladmin -u root -h centos64.ehowstuff.local password 'new-password'\r\n\r\nAlternatively you can run:\r\n\/usr\/bin\/mysql_secure_installation\r\n\r\nwhich will also give you the option of removing the test\r\ndatabases and anonymous user created by default.  This is\r\nstrongly recommended for production servers.\r\n\r\nSee the manual for more instructions.\r\n\r\nYou can start the MySQL daemon with:\r\ncd \/usr ; \/usr\/bin\/mysqld_safe &\r\n\r\nYou can test the MySQL daemon with mysql-test-run.pl\r\ncd \/usr\/mysql-test ; perl mysql-test-run.pl\r\n\r\nPlease report any problems with the \/usr\/bin\/mysqlbug script!\r\n\r\n                                                           [  OK  ]\r\nStarting mysqld:                                           [  OK  ]\r\n<\/pre>\n<h2>Securing MySQL Database Server<\/h2>\n<p>Securing your MySQL Database Server is a crucial step. This includes setting up the password for the MySQL root user, removing anonymous users, disallowing root login remotely, and removing the test database and access. You can do all of this by running the mysql_secure_installation script:<\/p>\n<pre>\r\n\/usr\/bin\/mysql_secure_installation\r\n<\/pre>\n<p>This script will guide you through the process of securing your MySQL installation. It will prompt you to set a root password, remove anonymous users, disallow root login remotely, and remove the test database and access.<\/p>\n<p>Example:<\/p>\n<pre>\r\n[root@centos64 ~]# \/usr\/bin\/mysql_secure_installation\r\n\r\n\r\n\r\n\r\nNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL\r\n      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!\r\n\r\n\r\nIn order to log into MySQL to secure it, we'll need the current\r\npassword for the root user.  If you've just installed MySQL, and\r\nyou haven't set the root password yet, the password will be blank,\r\nso you should just press enter here.\r\n\r\nEnter current password for root (enter for none):\r\nOK, successfully used password, moving on...\r\n\r\nSetting the root password ensures that nobody can log into the MySQL\r\nroot user without the proper authorisation.\r\n\r\nSet root password? [Y\/n] y\r\nNew password:\r\nRe-enter new password:\r\nPassword updated successfully!\r\nReloading privilege tables..\r\n ... Success!\r\n\r\n\r\nBy default, a MySQL installation has an anonymous user, allowing anyone\r\nto log into MySQL without having to have a user account created for\r\nthem.  This is intended only for testing, and to make the installation\r\ngo a bit smoother.  You should remove them before moving into a\r\nproduction environment.\r\n\r\nRemove anonymous users? [Y\/n] y\r\n ... Success!\r\n\r\nNormally, root should only be allowed to connect from 'localhost'.  This\r\nensures that someone cannot guess at the root password from the network.\r\n\r\nDisallow root login remotely? [Y\/n] y\r\n ... Success!\r\n\r\nBy default, MySQL comes with a database named 'test' that anyone can\r\naccess.  This is also intended only for testing, and should be removed\r\nbefore moving into a production environment.\r\n\r\nRemove test database and access to it? [Y\/n] y\r\n - Dropping test database...\r\n ... Success!\r\n - Removing privileges on test database...\r\n ... Success!\r\n\r\nReloading the privilege tables will ensure that all changes made so far\r\nwill take effect immediately.\r\n\r\nReload privilege tables now? [Y\/n] y\r\n ... Success!\r\n\r\nCleaning up...\r\n\r\n\r\n\r\nAll done!  If you've completed all of the above steps, your MySQL\r\ninstallation should now be secure.\r\n\r\nThanks for using MySQL!\r\n\r\n\r\n<\/pre>\n<h2>Testing the Installation<\/h2>\n<p>After securing your MySQL Database Server, you should test the installation by logging into the MySQL Server using the root password you defined earlier:<\/p>\n<pre>\r\nmysql -u root -p\r\n<\/pre>\n<p>You will be prompted to enter the root password. Once logged in, you can display the databases in your MySQL server by using the &#8220;show databases;&#8221; command.<\/p>\n<p>Example:<\/p>\n<pre>\r\n[root@centos64 ~]# mysql -u root -p\r\nEnter password:\r\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\r\nYour MySQL connection id is 10\r\nServer version: 5.1.69 Source distribution\r\n\r\nCopyright (c) 2000, 2013, Oracle and\/or its affiliates. All rights reserved.\r\n\r\nOracle is a registered trademark of Oracle Corporation and\/or its\r\naffiliates. Other names may be trademarks of their respective\r\nowners.\r\n\r\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\r\n\r\nmysql> show databases;\r\n+--------------------+\r\n| Database           |\r\n+--------------------+\r\n| information_schema |\r\n| mysql              |\r\n+--------------------+\r\n2 rows in set (0.01 sec)\r\n\r\nmysql>\r\n<\/pre>\n<h2>Commands Mentioned<\/h2>\n<ul>\n<li><span class=\"fw-bold\">yum install mysql mysql-server -y<\/span> \u2013 Installs MySQL server and client<\/li>\n<li><span class=\"fw-bold\">chkconfig mysqld on<\/span> \u2013 Sets the MySQL daemon to start at boot<\/li>\n<li><span class=\"fw-bold\">service mysqld start<\/span> \u2013 Starts the MySQL Database Server<\/li>\n<li><span class=\"fw-bold\">\/usr\/bin\/mysql_secure_installation<\/span> \u2013 Secures the MySQL Database Server<\/li>\n<li><span class=\"fw-bold\">mysql -u root -p<\/span> \u2013 Logs into the MySQL Server as root<\/li>\n<li><span class=\"fw-bold\">show databases;<\/span> \u2013 Displays the databases in the MySQL server<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Installing and securing MySQL on a CentOS 6.4 VPS or dedicated server is a straightforward process that involves a series of steps. By following this guide, you have learned how to install MySQL using the yum command, make the MySQL daemon start at boot, secure your MySQL Database Server, and test the installation by logging into the MySQL Server. <\/p>\n<p>Remember, securing your MySQL Database Server is a crucial step in protecting your data from unauthorized access.<\/p>\n<p>For more in-depth guides on web servers, you can visit our pages on <a href=\"https:\/\/webhostinggeeks.com\/blog\/apache-http-server-explained\/\">Apache<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/nginx-server-explained\/\">Nginx<\/a>, and <a href=\"https:\/\/webhostinggeeks.com\/blog\/litespeed-web-server-explained\/\">LiteSpeed<\/a>. If you&#8217;re interested in different types of hosting, we have detailed explanations on <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-dedicated-server-hosting\/\">dedicated server hosting<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-vps-hosting\/\">VPS hosting<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-cloud-hosting\/\">cloud hosting<\/a>, and <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-shared-hosting\/\">shared hosting<\/a>.<\/p>\n<p>Remember, the key to a successful web server setup lies in understanding the tools at your disposal and how to use them effectively.<\/p>\n<p>Happy hosting!<\/p>\n<h2>FAQs<\/h2>\n<ol itemscope itemtype=\"https:\/\/schema.org\/FAQPage\">\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the purpose of the yum command in the installation process?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The yum command is used in CentOS and other RPM-based Linux distributions to manage packages. In this context, it&#8217;s used to install the MySQL server and client on the system.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What does the mysql_secure_installation script do?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The mysql_secure_installation script is a security script that comes with MySQL. It&#8217;s designed to perform several important security-related operations such as setting a root password, removing anonymous users, disallowing root login remotely, and removing the test database and access.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Why is it important to secure the MySQL Database Server?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">Securing the MySQL Database Server is crucial to protect sensitive data from unauthorized access. By setting a strong root password, removing anonymous users, disallowing root login remotely, and removing the test database, you can significantly reduce the risk of a security breach.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">How can I verify that the MySQL Database Server has been installed correctly?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">You can verify the installation by logging into the MySQL Server using the root password you defined during the security setup. Once logged in, you can run the &#8220;show databases;&#8221; command to display the databases in your MySQL server.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the purpose of the chkconfig command in this process?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The chkconfig command is used to update and query runlevel information for system services. In this context, it&#8217;s used to ensure that the MySQL daemon starts automatically at boot.<\/span>\n            <\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>MySQL is one of the most widely used databases on the internet, particularly for content management and blogging sites. It stores and retrieves data for blogs, websites, and applications. This&#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":[2055,1008],"tags":[1244,1255,1585],"class_list":["post-4701","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-mysql","tag-centos","tag-centos-6-4","tag-mysql"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/4701","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=4701"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/4701\/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=4701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=4701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=4701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}