{"id":681,"date":"2019-12-11T19:56:30","date_gmt":"2019-12-11T19:56:30","guid":{"rendered":"http:\/\/jlavelle.uk\/pfw\/?p=681"},"modified":"2019-12-30T22:07:13","modified_gmt":"2019-12-30T22:07:13","slug":"fresh-mysql-install-access-denied-for-user-rootlocalhost","status":"publish","type":"post","link":"https:\/\/jlavelle.uk\/pfw\/fresh-mysql-install-access-denied-for-user-rootlocalhost\/","title":{"rendered":"Fresh MYSQL install, Access denied for user &#39;root&#39;@&#39;localhost&#39;"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Lets go through the install process:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>#install a complete LAMP Stack first then install phpmyadmin (note the ^ is important)\nsudo apt-get install lamp_stack^\n\n# Enable Apache2 to start on boot\nsudo systemctl enable apache2\n\n# Start Apache2 if it isn't started\nsudo systemctl start apache2\n\n# Add yourself to the the www-data Group and take ownership of the \/var\/www directory\nsudo usermod -a -G www-data $USER\nsudo chown -R $USER:www-data \/var\/www\/\n\n# Install phpmyadmin\nsudo apt-get install phpmyadmin javascript-common\n\n# Set root password for MySQL change NEWPASSWORD to your choice of password\nmysqladmin -u root password NEWPASSWORD\n<\/code><\/pre>\n\n\n\n<p>BANG &#8211; !! This gives the error !!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What&#8217;s happening?<\/h3>\n\n\n\n<p>If you install 5.7 and don\u2019t provide a password for the root user, MySQL will use the auth_socket plugin. That plugin doesn\u2019t need a password. It just checks if the user is connecting using a UNIX socket and then compares the username. If we want to configure a password, we need to change the plugin and set the password at the same time, <em>in the same command<\/em>. First changing the plugin and then setting the password won\u2019t work, and it will fall back to auth_socket again.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Right, let&#8217;s fix it!<\/h3>\n\n\n\n<p>You can&#8217;t fix it if you can&#8217;t login. So to login we need to find an administrator password. Luckily there is one!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Locate and copy the Debian System Maintenance password in this file\nsudo xed \/etc\/mysql\/debian.cnf\n\n# Now enter the following in terminal - you will be prompted for a password. Enter the password you just copied from \/etc\/mysql\/debian.cnf above\nmysql -u debian-sys-maint -p\n<\/code><\/pre>\n\n\n\n<p>Bingo, you&#8217;re in with full Administrator rights!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># At the mysql> prompts enter the following commands pressing enter after each one - change NEWPASSWORD to a password of your choice\nuse mysql;\nALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NEWPASSWORD';\nFLUSH PRIVILEGES;\nquit;\n<\/code><\/pre>\n\n\n\n<p>That&#8217;s it! Fixed. To test it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Login with the following command, you'll be prompted for your newly created password\nmysql -u root -p\n\n# To exit mysql> enter quit;\n\n# Now secure MySQL\nsudo \/usr\/bin\/mysql_secure_installation\n\n<\/code><\/pre>\n\n\n\n<p>I hope you found that useful.<\/p>\n\n\n\n<p>This post is also available as a <strong><em>&#8220;Gist&#8221;<\/em><\/strong>. You can find the gist here:  <a href=\"https:\/\/gist.github.com\/jlavelle-uk\/b61a7be76976939aec16799f9eea746f\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"https:\/\/gist.github.com\/jlavelle-uk\/b61a7be76976939aec16799f9eea746f (opens in a new tab)\">https:\/\/gist.github.com\/jlavelle-uk\/b61a7be76976939aec16799f9eea746f<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lets go through the install process: BANG &#8211; !! This gives the error !! What&#8217;s happening? If you install 5.7 and don\u2019t provide a password for the root user, MySQL will use the auth_socket plugin. That plugin doesn\u2019t need a password. It just checks if the user is connecting using a UNIX socket and then &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/jlavelle.uk\/pfw\/fresh-mysql-install-access-denied-for-user-rootlocalhost\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fresh MYSQL install, Access denied for user &#39;root&#39;@&#39;localhost&#39;&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,18,20,11,13],"tags":[35,28,31,33,27,32,30],"class_list":["post-681","post","type-post","status-publish","format-standard","hentry","category-apache-2","category-lampp","category-mysql","category-php","category-stacks","tag-fresh-mysql-install","tag-lamp-stack","tag-linux","tag-localhost","tag-mysql","tag-root","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/jlavelle.uk\/pfw\/wp-json\/wp\/v2\/posts\/681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jlavelle.uk\/pfw\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jlavelle.uk\/pfw\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jlavelle.uk\/pfw\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jlavelle.uk\/pfw\/wp-json\/wp\/v2\/comments?post=681"}],"version-history":[{"count":8,"href":"https:\/\/jlavelle.uk\/pfw\/wp-json\/wp\/v2\/posts\/681\/revisions"}],"predecessor-version":[{"id":691,"href":"https:\/\/jlavelle.uk\/pfw\/wp-json\/wp\/v2\/posts\/681\/revisions\/691"}],"wp:attachment":[{"href":"https:\/\/jlavelle.uk\/pfw\/wp-json\/wp\/v2\/media?parent=681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jlavelle.uk\/pfw\/wp-json\/wp\/v2\/categories?post=681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jlavelle.uk\/pfw\/wp-json\/wp\/v2\/tags?post=681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}