Fresh MYSQL install, Access denied for user 'root'@'localhost'

Lets go through the install process:

#install a complete LAMP Stack first then install phpmyadmin (note the ^ is important)
sudo apt-get install lamp_stack^

# Enable Apache2 to start on boot
sudo systemctl enable apache2

# Start Apache2 if it isn't started
sudo systemctl start apache2

# Add yourself to the the www-data Group and take ownership of the /var/www directory
sudo usermod -a -G www-data $USER
sudo chown -R $USER:www-data /var/www/

# Install phpmyadmin
sudo apt-get install phpmyadmin javascript-common

# Set root password for MySQL change NEWPASSWORD to your choice of password
mysqladmin -u root password NEWPASSWORD

BANG – !! This gives the error !!

What’s happening?

If you install 5.7 and don’t provide a password for the root user, MySQL will use the auth_socket plugin. That plugin doesn’t 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, in the same command. First changing the plugin and then setting the password won’t work, and it will fall back to auth_socket again.

Right, let’s fix it!

You can’t fix it if you can’t login. So to login we need to find an administrator password. Luckily there is one!

# Locate and copy the Debian System Maintenance password in this file
sudo xed /etc/mysql/debian.cnf

# 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
mysql -u debian-sys-maint -p

Bingo, you’re in with full Administrator rights!

# At the mysql> prompts enter the following commands pressing enter after each one - change NEWPASSWORD to a password of your choice
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NEWPASSWORD';

That’s it! Fixed. To test it:

# Login with the following command, you'll be prompted for your newly created password
mysql -u root -p

# To exit mysql> enter quit;

# Now secure MySQL
sudo /usr/bin/mysql_secure_installation

I hope you found that useful.

This post is also available as a “Gist”. You can find the gist here:

NetBeans 101 Series

There’s always a learning curve with every new program and NetBeans is no exception.

NetBeans 101 is an introduction on how to use the Netbeans IDEto develop programs. We will look at the how, the why and the where of the IDE and answer questions like “What does this do?”, “How do I configure it?” and “Why would I need it?”.

If you haven’t used an IDE previously this series will guide you through how to use NetBeans effectively and efficiently. Conversely, if you’ve used an IDE in the past, like Delphi RAD Studio or Microsoft’s Visual Studio, this series will show you where to find things and how to integrate them into your project. And, if you already use NetBeans, there may be tips, tricks and easier ways to do things you didn’t know about.


An IDE is much more than a text editor. The NetBeans Editor indents lines, matches words and brackets, and highlights source code syntactically and semantically. It lets you easily Refactor code, with a range of useful and powerful tools, it also provides code templates, coding tips, and code generators.

We’ll also look at writing programs with NetBeans. How to use the Testing plugins. How to write plugins. How to use the Team facilities like Git and BitBucket. Connecting to Databases like MySQL. Creating Templates, using and editing Code Templates and much, much more.

There will be a separate video for each item so you won’t have to trawl through hours of video to find the section you want.

Come along for the ride!


First Post

Well Hello and Welcome to this site!

Have you ever wanted Tips and Tricks on a particular subject and had to visit countless sites to find all the answers? I know I have.

What Programming for the Web is attempting to do is to bring as many of the tips and tricks about Web Programming together into one place.

Each article usually contains a video and step-by-step instructions. 

The articles will cover topics like:

  • HTML
  • CSS (SASS & Less)
  • JavaScript
  • PHP
  • SQL
    • MySQL
    • MariaDB
  • IDEs (NetBeans etc.)
    • Installation
    • Configuration
    • Shortcuts and “How to’s”
  • Text Editors (Atom, VS Code, Sublime Text etc.)
  • Web Servers (Apache)
    • Installation
    • Configuration
    • Security
    • htaccess
    • Installation
    • Configuration
    • Security
    • htaccess
  • Linux (most web servers run on Linux or Unix)
  • Repurposing old Laptops and Computers
  • Using the Raspberry Pi as:
    • a “staging server”
    • to develop web applications
  • Later articles will look at:
    • Python
    • Java

The articles assume a little knowledge but not necessarily about web programming.

There will also be Book Reviews and reviews of new and updated programming languages, IDEs, Editors etc.

To date (28th November 2018) there are 82 articles available on YouTube and, soon, those articles will also be available on this site.

If you have a specific request, please leave a comment below and I’ll try to post an article as soon as I can.

Don’t forget to Bookmark this site so you can easily find it in the future.

Thank you for visiting.