weird behaviour of mysql after running mysql_secure_installation - mysql

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?

Related

I can log into my MySQL database as root via MySQL workbench, but not from the command line

Please help me on this problem.
I installed mysql and workbench, but when i run mysql -u root -p and gives password, it gives error : ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES) but when i using workbench log into the database, it works fine.
There is several things you want to know first
-I had installed xampp before, (i already uninstalled xampp,but doesn't help)
-root is running on port 3307 as 3306 was already occupied.
-I have tried : set password for root="password"; but it gives ERROR 1044 (42000): Access denied for user ''#'localhost' to database 'mysql'
-I am using windows 10 and using another user account not administator
-I am running the mysql version 8.0
I am new to these stuff. I searched for days and coudn't find any solution. help me. thanks

After import a mysqldump can't access to MySQL with root or any created user

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

How to specify default user in mac OS when running the mysql command in terminal?

I'm on mac OS Catalina 10.15.2 with a fresh install of mysql. I'm getting the following output when running the commands mysql or mysql -v:
ERROR 1045 (28000): Access denied for user 'timothyfisher'#'localhost' (using password: NO)
This is because the user isn't set to root in my case. MySQL works just fine as I can enter with mysql -u root, so this isn't really causing any problems but it gets kind of annoying.
How can I set the mysql command to use the root user instead of my computer user?
Create file ~/.my.cnf and add following lines.
[client]
user=<your_user>
password=<your_password>
More info can see https://easyengine.io/tutorials/mysql/mycnf-preference/.

Access denied mysql server

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?

Why is mysql (all the sudden) translating 127.0.0.1 to localhost internally?

I have a strange issue with mysql. I want to connect to the database using the mysql client, and since I want to force connection via TCP I do this:
$ mysql --protocol=TCP -uroot -p -h127.0.0.1
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
As you can see, the connection fails, because there is no root access defined for 'root'#'localhost'. This is true - I did not GRANT any privileges to this hostname. However I did specify the root account with full privileges for 'root'#'127.0.0.1'.
I was able to connect to the database in the past with the above mentioned command. However, now it fails. I am not sure if a system update happened in between but something must have changed.
Does anyone have a solution? I would rather not stop the database server for that if possible.
Some more background info. This is running the mysql flavor percona server 5.6 on an ubuntu 14.04 LTE box with everything up to date.