A few years ago I wanted to learn MySQL and installed MySQL Community on Fedora Linux. Today, I'm needing it for a project, but I can't remember any users or passwords. I removed it through dnf and installed it again. I started the server through systemctl and ran mysql_secure_installation. It prompted:
Securing the MySQL server deployment.
Enter password for user root:
I typed a new password and it issued an error:
Error: Access denied for user 'root'#'localhost' (using password: YES)
I tried to remove MySQL again, delete the /var/lib/mysql folder and reinstall it again. Still, no success, it keeps issuing the same error.
Could anybody help me install MySQL and configure it properly, please?
Im not using fedora, but i think same way as other linux
you should type console "mysql -u root -p" where -u is a user and -p is a password, I think you not used -p or maybe my mistake then need more information how did you try to access to database.
have a nice day :)
Related
I have different ubuntu servers running mysql 8.
After installing the server I use to secure the installation with the same settings for all the servers.
First of all I disable the possibility for root to login remotely. After this change the command:
sudo mysql
will make me login with root user from the server shell while running
mysql -uroot -p
will keep me out and this is the expected behaviour.
On one server I run mysql_secure_installation with the usual procedure and everything worked as expected but:
sudo mysql
will keep me out with the message:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
while
mysql -uroot -p
will log me in normally (exactly the opposite of what I expect to be)
Where should I look for to solve this? Did anyone face the same issue before?
I installed via brew on macos the package mysql#5.7 so that can work with Laravel, following the present documentation but I cannot access to mysql#5.7
$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
the documentation says
Database
If you need a database, try MySQL by running brew install mysql#5.7 on
your command line. Once MySQL has been installed, you may start it
using the brew services start mysql#5.7 command. You can then connect
to the database at 127.0.0.1 using the root username and an empty
string for the password.
I made a long research and found that is a really common problem but whatever thing I tried did not work
I launched mysqld skipping flushing privileges but then cannot root as well with mysql -u root -p
I tried to run a php artisan cache:clear
I tried to use sudo -s to log as root
and other things that at the moment do not remember anymore(basically is 3 days I am busy)
I am really surprised that a framework as Laravel that should be easy, has this kind of problems that are not reported by the documentation tutorial nor laracast, I did not do nothing strange, just followed the guide
I saw a post where for this error was suggested to change password, but also in this case I went through some issue, so I had to combine different responses but now works
I followed mainly this post
but arrived to the point 5:
5 : modify your password your new password should be input in "()"
I had to deal with a change in mysql#5.7 namely if you do show tables you see that there is not a password column anymore, so you get an error message that does not exist the column password,
so I just passed
update user set authentication_string=password('1111') where user='root';// please notice 1111 is the password you fill
as indicated in this other post
then I followed the other step indicated by the post, to flush privileges and quit
finally I started again the daemon with
$brew services start mysql#5.7 and $mysql -u root -p (herethepassword)
did not work so I did
$mysql --password=(herethepassword) --user=root
and worked
Background: I use vagrant (Ubuntu 18.04) to create my development environment,I'm install PHP, MySQL and other stuff but recently I got the problem that I can access to mysql and then I got the classic error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using
password: NO)
using sudo mysql or
ERROR 1045 (28000): Access denied for user 'otheruser'#'localhost'
(using password: YES)
when trying mysql -u otheruser -p
The problems is that MySQL is working fine for a fews 'vagrant up' and 'vagrant halt' but for some reason when I start the box again I can't access to MySQL anymore. I know that I can reset the MySQL root password, remove MySQL or do another quick solution, but most of all I want to know what is the cause of the problem because at first I was thinking about something related to an update I done to my vagrant box, or an update on Ubuntu.
When I install mysql on that Box with Ubuntu I use a .sh file to automate the process, here is the section of mysql:
# Mysql Instalation
sudo apt install mysql-server -y
sudo mysql_secure_installation
sudo mysql < setup.sql
and the setup.sql :
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'rootpassword';
FLUSH PRIVILEGES;
CREATE USER 'otheruser'#'localhost' IDENTIFIED BY 'otherpassword';
GRANT ALL PRIVILEGES ON * . * TO 'otheruser'#'localhost';
FLUSH PRIVILEGES;
Then I tried to figure out what the problem and tried to resolve it, first I commented the lines of the root statement on the setup.sql file and then later commenting the 'mysql_secure_installation' line on the .sh file but the problems persists; so to solve quickly I destroy the box and then I create it again, but this turned boring at this point, so here I'm here to describe my problem.
so resuming the questions are:
What could be the cause of the problem?, so I can resolve it on future box creations.
What is the best way to solve this kind of problem.
Because it is overwhelming create and destroy the box every time the problem occurs and most important when I move an app to a production server I don't want this kind of problems.
Thanks for your time reading this. Have a nice day.
Update 06/Feb/2020
After review my deploy process to find more information about the problem I find out that the problem starts when I do an import from a mysqldump
from my production server; just after the import and do a vagrant halt and vagrant up again the problem occurs so Im unable to login on MySQL again.
Here is my mysqldump process and my import process to help is there is something wrong.
Production Server with Ubuntu 16.04 MySQL 5.7.29
mysqldump -u root -p --all-databases > alldb_04-02-2020.sql
Vagrant Box with Ubuntu 18.04 MySQL 5.7.29
mysql -u otheruser -p < alldb_04-02-2020.sql
Well, there is always surprise with newer versions of software. This time they are Ubuntu 18.04 and Mysql. I followed every step https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-on-ubuntu-18-04. Now sudo mysql -u root -p gives access denied error. Can't log in to phpmyadmin too. Cheers!!! Spend hours to solve but nothing.
--------------------------------------/
I got my fault. Tutorial says to run ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';. It looks like password is auth method, but it turns out it is password itself, that is, after mysql -u root -p you need enter password
I am trying to set up mysql on my Mac, but every time I type mysql on the command line I get:
ERROR 1045 (28000): Access denied for user 'arlet'#'localhost' (using
password: NO)
I type mysql -u root -p, and I get the same error.
I do not know if the server was set up correctly, because in the tutorial I am watching they activated it from preferences but in the installation package I got I did not have that option.
When I installed it I got a password and did not write it down, so I tried to reset it using the instructions in the manual Resetting the Root Password: Unix and Unix-Like Systems and no results. Please help.
Edit: Alright, I think it's best to delete mysql from my computer and reinstall it. I have tried sudo rm /usr/local/mysql and it does not work. How can I remove it?