ERROR 1045 (28000) Access denied for user Ubuntu

MySQL Error Ubuntu Linux

This error message ERROR 1045 (28000) Access denied for user (using password: NO) occurred when I made an error after installing MySQL on my Ubuntu Linux Operating system.

Even though when I type mysql the error still appears. So I can’t do anything.

neon@linux:~$ mysql
ERROR 1045 (28000): Access denied for user 'neon'@'localhost' (using password: NO)

To fix this has been described on stackoverflow, But I copy that for personal notes. It happens when your password is missing.

Ubuntu ERROR 1045 (28000) Access denied for user MySQL

Steps to change the password when you have forgotten it:

1. Stop MySQL Server

Stop MySQL Server using this command:

sudo systemctl stop mysql
## or ##
sudo service mysql stop

2. Start The Database

Start the database without loading the grant tables or enabling networking:

sudo mysqld_safe --skip-grant-tables --skip-networking &

The ampersand at the end of this command will make this process run in the background, so you can continue to use your terminal and run :

mysql -u root

It will not ask for a password.

If successful like as below:

neon@linux:~$ 2022-09-07T09:51:30.128591Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2022-09-07T09:51:30.163459Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.30-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

And go to step 5.

If you get error like as below:

neon@linux:~$ 2022-09-07T07:34:38.505429Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2022-09-07T07:34:38.508335Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

[1]+  Exit 1

Go to step 3.

3. Make MySQL Direcory

Make MySQL service directory using this command:

sudo mkdir /var/run/mysqld

Give MySQL user permission to write to the service directory.

sudo chown mysql: /var/run/mysqld

4. Back to step 2

Run the same command in step 2 to run MySQL in background.

5. Remove MySQL Password

Now, to remove the password use this command:

a. Remove Password ( > 5.7.6 version)

mysql> SET PASSWORD FOR root@localhost='';

b. remove Password ( < 5.7.6 version)

mysql> SET PASSWORD FOR root@localhost=PASSWORD('');

c. Now Exit

mysql> quit
## and/or ##
mysql> exit

6. Login to MySQL

To login to mysql service use this command:

sudo mysql

If successful you will see:

neon@linux:~$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 8.0.30-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

I hope this ERROR 1045 (28000) Access denied for user article is usefull for you.

Read more:
> Install Laravel First Time In Ubuntu Linux
> React Script is not recognized an internal Command
> Install latest Node JS Ubuntu Terminal Easy 2022

Scroll to Top