Access deined while configuring mysql ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO) - ubuntu-20.04

I am following this post on How to Install MySQL on Ubuntu 20.04 LTS?
Updated package index sudo apt update
Installed MySQL server sudo apt install mysql-server
Configuring MySQL sudo mysql_secure_installation, entered password
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Connect to MySQL server
When I use this sudo mysql, I get the following error shown below
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
When I use this sudo mysql -u root, I get the following error shown below
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
When I use this mysql, I get the following error shown below
ERROR 1045 (28000): Access denied for user 'username'#'localhost' (using password: NO)
When I use this sudo mysql -u root -p, I get the following error shown below
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I tried resetting the password following official Mysql B.3.3.2 How to Reset the Root Password and How to Change MySQL Root Password in Ubuntu 20.04
Stopped server sudo systemctl stop mysql.service
Checked the status sudo systemctl status mysql.service
Skipped the grant tables & networking sudo systemctl set-environment MYSQLD_OPTS="--skip-networking --skip-grant-tables"
Started server sudo systemctl start mysql.service
Checked the status sudo systemctl status mysql.service
Sign in to MySQL shell sudo mysql -u root, I get the same error
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
What is the mistake? How do I correct it?

When you are here: mysql_secure_installation try to insert the password:"rootroot"
In mac is assigned by default.

Related

Why I can't connect to mysql docker locally with Laravel?

I follow the official documentation for Windows at https://laravel.com/docs/9.x#getting-started-on-windows.
curl -s https://laravel.build/example-app | bash
cd example-app
./vendor/bin/sail up
Containers are fine and running. I open mysql command line and run:
mysql -h localhost -u root -p
I enter no password (just enter) and I get:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)

#1045 - Access denied

MySQL said:
1045 - Access denied for user 'root'#'localhost' (using password: YES)
mysqli_real_connect(): (28000/1045): Access denied for user 'root'#'localhost' (using password: YES)
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL

createuser: could not connect to database postgres:

I am trying to create a user in PostgreSQL in Mac with the following command
createuser -P project_user
It then prompts
Enter password for new role:
Enter it again:
Password:
I enter thrice the new password for project_user but authentication fails with the below error.
createuser: could not connect to database postgres: FATAL: password authentication failed for user <my_mac_user_name>.
I was able to enter psql terminal with following command and password as 'postgres'
sudo -u postgres psql
\du displays the user project_user.
But same error appears when trying to create database with below command
createdb -O project_user DB_NAME

Homestead error: The SSH command responded with a non-zero exit status

I get an error when I do homestead up --provision on my homestead machine:
...[success logs here]...
==> default: Running provisioner: shell...
default: Running: /var/folders/9j/bsvhbzdn2dx8hjwgnl7nrj7w0000gn/T/vagrant-
shell20170127-4343-1dyyzgz.sh
==> default: mysql:
==> default: [Warning] Using a password on the command line interface
can be insecure.
==> default: Please use --connect-expired-password option or invoke
mysql in interactive mode.
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
Although I get this error, everything works fine except one:
Databases that I have defined in ~/.homestead/Homestead.yaml are not created in mysql. So I guess this error causes the issue.
Any help would be appreciated.
I believe this is actually due to MySQL having an expiration time on passwords rather than having them last forever. It seems to happen for me when I'm running my old Laravel Homestead 5 box instead of newer ones for Homestead 7+.
Note that the following solution also fixes ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
From the host machine:
vagrant up
# ignore "SSH command responded with a non-zero exit status"
vagrant ssh
Now within the client machine:
# log into mysql (for Homestead your password is likely "secret")
mysql -h localhost -u homestead -p
SET PASSWORD = PASSWORD('secret');
-- A) set password to never expire:
ALTER USER 'root'#'localhost' PASSWORD EXPIRE NEVER;
-- or B) to change password as well:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'new_password', 'root'#'localhost' PASSWORD EXPIRE NEVER;
-- quit mysql
quit
# exit back to host shell
exit
Now from the host machine:
vagrant up --provision
And it should work.
However, if you now see ==> default: createdb: database creation failed: ERROR: database "homestead" already exists then run this line within the client machine:
mysql -h localhost -u homestead -p -e "DROP DATABASE homestead"
Then run vagrant up --provision from the host machine and be on your way.

ERROR 1045 (28000): Access denied for user 'users'#'host'

Mysql is making me crazy....
I know that this question has been asked 1000 times but nothing works for me... I can't connect to mysql ! This arrived after I update ubuntu 13.1
$> mysql
ERROR 1045 (28000): Access denied for user 'jeremy'#'localhost' (using password: NO)
$> mysql -u root -p****
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
$> cd my_work ; rails c
Access denied for user 'working'#'localhost' (using password: YES) (Mysql2::Error)
I have tried a thousand of command lines, the only thing that not show me a permission denied is to run mysqld with the --skip-grant-tables option but once started, It is like I have no users in my db, even root user ! More, I could not create or update users because of the --skip-grant-tables
$> sudo su
$> service mysql stop
$> mysqld --skip-grant-tables --skip-networking &
$> UPDATE user SET password=PASSWORD('********') WHERE user="root";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
$> SELECT host, user, password FROM user;
localhost | debian-sys-maint | *5480DE723DE487F407399B5208AA09588E67850E
Are all my users deleted ? Is my root user deleted ? How to fix that ?!
for #user2503775, my database.yml :
development:
encoding: utf8
adapter: mysql2
reconnect: true
database: working
username: working
password: working
socket: /var/run/mysqld/mysqld.sock

Resources