Access denied on mysql#5.7 - mysql

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

Related

Reinstalled MySQL, mysql_secure_install results in access denied

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 :)

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

Can not log in with root user to mysql in Ubuntu 18.04

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

How to install mysql to run as non-root

I have tried to install mysql, and then to run with
mysql -u root -p
but I get
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
I can get in with sudo, but I don't want to run as root. How do I get to run mysql as non-root?
I am using Linux Mint 19.1 32-bit.
What I tried:
sudo apt-get install mysql-client
sudo apt-get install mysql-server
sudo /etc/init.d/mysql restart
sudo mysql_secure_installation
Set up VALIDATE PASSWORD? No
Remove anonymous users? No
Disallow root login remotely? Yes
Remove test database and access to it? No
Reload privilege tables now? Yes
Then I try
mysql -u root -p
it asks for the password, I give the same one I gave in mysql_secure_installation...
frank#frank-laptop:~/WebDev$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
Gah.
I have reinstalled mysql client and server several times now, doing a complete uninstall between and getting rid of all databases when asked. I don't get asked for a root password during the install. That seems to be normal for an install in Ubuntu and derivatives, hence the mysql_secure_installation to set the password.
I tried following
http://www.yolinux.com/TUTORIALS/LinuxTutorialMySQL.html
I tried searching on the web for hints, e.g.
https://askubuntu.com/questions/766900/mysql-doesnt-ask-for-root-password-when-installing#766908
and others but I have not been able to get mysql to start without sudo. If I do use sudo I can create a database, add tables and add data so the database is installed, I just need more privilege to run it than I think I should need.
Anywhere I looked, the instructions go from installation to starting mysql without anything special between, so I think I must be doing something quite stupid. But I have not been able to figure out what.
The first time you run mysql -u root -p , you have to run it with sudo in order to create a new user:
DROP USER 'root'#'localhost';
CREATE USER 'XXX'#'%' IDENTIFIED BY 'YYY';
GRANT ALL PRIVILEGES ON *.* TO 'XXX'#'%' WITH GRANT OPTION;
Then you can connect yourself using mysql --user=XXX --password=YYY
I already try but I don't think you can setup your DB without using sudo unfortunately.

Mysql 5.7.17 root password forgotten / no access to mysql command line on Mac

I downloaded MySQL 5.7.17 for Mac and installed it. I can start and stop the SQL server from my Preferences > MySQL. It is shown as an instance on port 3306 from Workbench so all that seems fine. However, during install toward the end a pop-up window listed a password I was supposed to use. I assumed it would be promptly needed so copied on the clipboard. Few mins later having not been prompted for it yet, I copied something else in the clipboard thus losing it.
I have been trying to get some sort of client of mysql command line so I can enter sql commands, however there is no "Application" installed to use to access the server. I have scoured the MySQL documentation and Stack and beyond, and searched for how to get the password reset, and a mysql client/command line, but all the articles seem to assume you already have access to a "MySQL terminal"/"command line". I only have access to my normal Mac Terminal, and most commands in the normal Terminal window either fail or require the password I don't have, for example:
$ mysqld --skip-grant-tables
-bash: mysqld: command not found
$ mysql -u root -p
-bash: mysql: command not found
$ sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'
Password: (this is probably the password I was given that got overwritten? When I try the admin password of the machine it sends me back to the prompt)
$ sudo mysqld_safe --skip-grant-tables (after I'd stopped the server)
sudo: mysqld_safe: command not found
Can somebody please help me figure out how to get to a "MySql Terminal" and if I need this password that got overwritten, how to reset it? (it seems like uninstalling MySQL to repeat the steps and this time take better care of the password is actually horrendously difficult / no uninstall protocol?).
Thank you so very much.
--- Update: I used the How To Uninstall suggested by Josh M and then re-installed. This time I saved the password (so far, not sure how / where I need to use it). However, I must really be missing something b/c I still can't get access to mysql.
/usr/local/mysql/bin/mysql
ERROR 1045 (28000): Access denied for user 'Robert'#'localhost' (using password: NO)
Then I did $ export PATH=$PATH:/usr/local/mysql/bin but I still get ERROR 1045.
Try these set of commands
$ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables
/usr/local/mysql/bin/mysql
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'YOUR_NEW_PASSWORD';
EXIT;
$ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/support-files/mysql.server start
$ mysql -u root -p
$ Enter Password: 👉🏻 ENTER_YOUR_NEW_PASSWORD_HERE 👈🏻
And enjoy 🎉
There's a tutorial for resetting passwords here: https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords
Your MySQL command line interface (cli) is probably at:
/usr/local/mysql/bin/mysql
Honestly it might be better to reinstall. There's an SO on that: How do you uninstall MySQL from Mac OS X?