{"id":6959,"date":"2017-09-06T11:41:32","date_gmt":"2017-09-06T03:41:32","guid":{"rendered":"http:\/\/rmohan.com\/?p=6959"},"modified":"2017-09-06T11:41:32","modified_gmt":"2017-09-06T03:41:32","slug":"mysql","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6959","title":{"rendered":"Mysql"},"content":{"rendered":"<p>wget http:\/\/repo.mysql.com\/mysql-community-release-el7-5.noarch.rpm<br \/>\nrpm -ivh mysql-community-release-el7-5.noarch.rpm<br \/>\nyum update<br \/>\nyum install mysql-server<\/p>\n<p>systemctl start mysqld<\/p>\n<p>[root@clusterserver1 ~]# systemctl start mysqld<br \/>\n[root@clusterserver1 ~]# systemctl enable mysqld<br \/>\n[root@clusterserver1 ~]# systemctl status mysqld<\/p>\n<p>[root@clusterserver1 ~]# mysql_secure_installation<\/p>\n<p>NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL<br \/>\n      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!<\/p>\n<p>In order to log into MySQL to secure it, we&#8217;ll need the current<br \/>\npassword for the root user.  If you&#8217;ve just installed MySQL, and<br \/>\nyou haven&#8217;t set the root password yet, the password will be blank,<br \/>\nso you should just press enter here.<\/p>\n<p>Enter current password for root (enter for none):<br \/>\nOK, successfully used password, moving on&#8230;<\/p>\n<p>Setting the root password ensures that nobody can log into the MySQL<br \/>\nroot user without the proper authorisation.<\/p>\n<p>Set root password? [Y\/n] y<br \/>\nNew password:<br \/>\nRe-enter new password:<br \/>\nPassword updated successfully!<br \/>\nReloading privilege tables..<br \/>\n &#8230; Success!<\/p>\n<p>By default, a MySQL installation has an anonymous user, allowing anyone<br \/>\nto log into MySQL without having to have a user account created for<br \/>\nthem.  This is intended only for testing, and to make the installation<br \/>\ngo a bit smoother.  You should remove them before moving into a<br \/>\nproduction environment.<\/p>\n<p>Remove anonymous users? [Y\/n] y<br \/>\n &#8230; Success!<\/p>\n<p>Normally, root should only be allowed to connect from &#8216;localhost&#8217;.  This<br \/>\nensures that someone cannot guess at the root password from the network.<\/p>\n<p>Disallow root login remotely? [Y\/n] y<br \/>\n &#8230; Success!<\/p>\n<p>By default, MySQL comes with a database named &#8216;test&#8217; that anyone can<br \/>\naccess.  This is also intended only for testing, and should be removed<br \/>\nbefore moving into a production environment.<\/p>\n<p>Remove test database and access to it? [Y\/n] y<br \/>\n &#8211; Dropping test database&#8230;<br \/>\nERROR 1008 (HY000) at line 1: Can&#8217;t drop database &#8216;test&#8217;; database doesn&#8217;t exist<br \/>\n &#8230; Failed!  Not critical, keep moving&#8230;<br \/>\n &#8211; Removing privileges on test database&#8230;<br \/>\n &#8230; Success!<\/p>\n<p>Reloading the privilege tables will ensure that all changes made so far<br \/>\nwill take effect immediately.<\/p>\n<p>Reload privilege tables now? [Y\/n] y<br \/>\n &#8230; Success!<\/p>\n<p>All done!  If you&#8217;ve completed all of the above steps, your MySQL<br \/>\ninstallation should now be secure.<\/p>\n<p>Thanks for using MySQL!<\/p>\n<p>Cleaning up&#8230;<br \/>\n[root@clusterserver1 ~]# systemctl restart mysqld<\/p>\n<p>[root@clusterserver1 ~]# mysql -u root -p<br \/>\nEnter password:<br \/>\nWelcome to the MySQL monitor.  Commands end with ; or \\g.<br \/>\nYour MySQL connection id is 2<br \/>\nServer version: 5.6.33 MySQL Community Server (GPL)<\/p>\n<p>Copyright (c) 2000, 2016, Oracle and\/or its affiliates. All rights reserved.<\/p>\n<p>Oracle is a registered trademark of Oracle Corporation and\/or its<br \/>\naffiliates. Other names may be trademarks of their respective<br \/>\nowners.<\/p>\n<p>Type &#8216;help;&#8217; or &#8216;\\h&#8217; for help. Type &#8216;\\c&#8217; to clear the current input statement.<\/p>\n<p>mysql><\/p>\n<p>create database testdb;<br \/>\ncreate user &#8216;testuser&#8217;@&#8217;localhost&#8217; identified by &#8216;password&#8217;;<br \/>\ngrant all on testdb.* to &#8216;testuser&#8217; identified by &#8216;password&#8217;;<\/p>\n<p> mysql> create database testdb;<br \/>\nQuery OK, 1 row affected (0.00 sec)<\/p>\n<p>mysql> create user &#8216;testuser&#8217;@&#8217;localhost&#8217; identified by &#8216;password&#8217;;<br \/>\nQuery OK, 0 rows affected (0.00 sec)<\/p>\n<p>mysql> grant all on testdb.* to &#8216;testuser&#8217; identified by &#8216;password&#8217;;<br \/>\nQuery OK, 0 rows affected (0.00 sec)<\/p>\n<p>mysql><\/p>\n<p>create database testdb;<br \/>\ngrant all on testdb.* to &#8216;testuser&#8217; identified by &#8216;password&#8217;;<\/p>\n<p>mysql -u testuser -p<\/p>\n<p>use testdb;<br \/>\ncreate table customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);<\/p>\n<p>[root@clusterserver1 ~]# mysql -u testuser -p<br \/>\nEnter password:<br \/>\nWelcome to the MySQL monitor.  Commands end with ; or \\g.<br \/>\nYour MySQL connection id is 4<br \/>\nServer version: 5.6.33 MySQL Community Server (GPL)<\/p>\n<p>Copyright (c) 2000, 2016, Oracle and\/or its affiliates. All rights reserved.<\/p>\n<p>Oracle is a registered trademark of Oracle Corporation and\/or its<br \/>\naffiliates. Other names may be trademarks of their respective<br \/>\nowners.<\/p>\n<p>Type &#8216;help;&#8217; or &#8216;\\h&#8217; for help. Type &#8216;\\c&#8217; to clear the current input statement.<\/p>\n<p>mysql> use testdb;<br \/>\nDatabase changed<br \/>\nmysql> create table customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);<br \/>\nQuery OK, 0 rows affected (0.01 sec)<\/p>\n<p>mysql><\/p>\n<p>Reset the MySQL Root Password<\/p>\n<p>If you forget your root MySQL password, it can be reset.<\/p>\n<p>    Stop the current MySQL server instance, then restart it with an option to not ask for a password.<\/p>\n<p>    systemctl stop mysqld<br \/>\n    mysqld_safe &#8211;skip-grant-tables &#038;<\/p>\n<p>    Reconnect to the MySQL server with the MySQL root account.<\/p>\n<p>    mysql -u root<\/p>\n<p>    Use the following commands to reset root\u2019s password. Replace password with a strong password.<\/p>\n<p>    use mysql;<br \/>\n    update user SET PASSWORD=PASSWORD(&#8220;password&#8221;) WHERE USER=&#8217;root&#8217;;<br \/>\n    flush privileges;<br \/>\n    exit<\/p>\n<p>    Then restart MySQL.<\/p>\n<p>    systemctl start mysqld<\/p>\n<p>Tune MySQL<\/p>\n<p>MySQL Tuner is a Perl script that connects to a running instance of MySQL and provides configuration recommendations based on workload. Ideally, the MySQL instance should have been operating for at least 24 hours before running the tuner. The longer the instance has been running, the better advice MySQL Tuner will give.<\/p>\n<p>    Download MySQL Tuner to your home directory.<\/p>\n<p>wget https:\/\/raw.githubusercontent.com\/major\/MySQLTuner-perl\/master\/mysqltuner.pl<\/p>\n<p>    To run it:<\/p>\n<p>perl .\/mysqltuner.pl<\/p>\n<p>You will be asked for the MySQL root user\u2019s name and password. The output will show two areas of interest: General recommendations and Variables to adjust.<\/p>\n<p>MySQL Tuner is an excellent starting point to optimize a MySQL server but it would be prudent to perform additional research for configurations tailored to the application(s) utilizing MySQL on your Linode.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>wget http:\/\/repo.mysql.com\/mysql-community-release-el7-5.noarch.rpm rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update yum install mysql-server<\/p>\n<p>systemctl start mysqld<\/p>\n<p>[root@clusterserver1 ~]# systemctl start mysqld [root@clusterserver1 ~]# systemctl enable mysqld [root@clusterserver1 ~]# systemctl status mysqld<\/p>\n<p>[root@clusterserver1 ~]# mysql_secure_installation<\/p>\n<p>NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!<\/p>\n<p>In order to [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6959"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6959"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6959\/revisions"}],"predecessor-version":[{"id":6960,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6959\/revisions\/6960"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}