Unable to log into mysql using password - Ubuntu - mysql

I installed mysql in Ubuntu 20.04.
Problem -
Case 1: I have default root user. I can login using sudo mysql but cannot login using mysql -u root -p.
Case 2: I created another user 'local'. I can login using mysql -u local -p and by giving password I set. But problem is if I give wrong password, it still logs me in. I don't know why.
I followed this ERROR 1698 (28000): Access denied for user 'root'#'localhost'
but this didn't help me. I followed other topics too like creating new user for mysql etc.
I cannot access from workbench or from python script too.
Error : ERROR 1698 (28000): Access denied for user 'root'#'localhost'

Login to mysql using sudo mysql -u root
Give your su password and it will login without mysql password.
Run following commands:
USE mysql;
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
FLUSH PRIVILEGES;
exit;
Restart:
sudo systemctl restart mysql.service
After that, run commands to secure MySQL server and create a new root password.
sudo mysql_secure_installation
When prompted, answer the following questions :
New password: Enter password
Re-enter new password:
Repeat password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
Next time, type following command in terminal to login:
sudo mysql -u root -p
Then type mysql password you set recently to sign in.
Good Luck, this worked for after continuous wasting several hours on this thing and following tens of tutorials.
By doing this, I was finally able to establish connection in workbench and in my python scripts.

Related

Mysql root user has no privileges

I've searched a lot but nothing works for me.
I have a fresh installation of a LAMP server, installed via tasksel command.
My system runs php 7.4 and MySql 8
For some reason root user (that in my case is called phpmyadmin, by default) has no privileges on the DBs.
I can log in, so I'm sure the password is correct, but I cannot create a Database.
$ mysql -u phpmyadmin -p
mysql > create database test;
Access denied for user 'phpmyadmin'#'localhost' to database 'test'
EDIT
As suggested, here's the output of
mysql> SELECT name, Create_priv FROM mysql.user;
SELECT command denied to user 'phpmyadmin'#'localhost' for table 'user'
NEW EDIT
I tried to access without the password, following the guide reported here:
...
No results for me :(
Stop the MySQL Server: sudo /etc/init.d/mysql stop (OK)
Start the mysqld configuration: sudo mysqld --skip-grant-tables
output:
[2] 2345
[1] Exit 1 sudo mysqld --skip-grant-tables
Run: sudo service mysql start
output
[2]+ Exit 1 sudo mysqld --skip-grant-tables
It seems to exit with errors... Am I wrong?
I also tried to login in that situation, but I receive this message "ERROR 1698 (28000) Access denied for user 'root'#'localhost'"
If I try my phpmyadmin user, the message is "ERROR 1045 (28000): Access denied for user 'phpmyadmin'#'localhost' (using password: NO)"
EDIT 06/19/2020
I followed the steps reported here
How to reset or change the MySQL root password?
I had to use MD5() instead of PASSWORD() because it's now deprecated.
There's still something wrong.
Now I can access the database with no privileges and set/change my password.
Then I can flush all privileges.
Then I try...
mysql -u root -p
I enter my new password...
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
I can still log in with the user set in phpMyAdmin, but there are still no privileges for me.
I also reinstalled MySql server.
I remember I had a similar problem last time I installed an old Linux Virtual Machine, but I solved that issue easily. Now I'm wondering what's wrong :(
SOLVED
I reinstalled my virtual machine and installed manually both php and mysql server.
To be sure to set privileges in the right way I followed this small guide... maybe helpful for someone.
https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-20-04
Bye!

Unable to log into mysql as root on OpenWRT

I finally decided to post my question as I am encountering high difficulties to connect to the mysql client.
I am using a mySQL database on an OpenWRT OS installed on an Arduino Yun.
I cannot log into mySQL as root, the following error message is displayed:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using
password: NO)
I tried with suffix -u root (or -uroot) and suffix -p and a supposed password but every time it turns out to be the same error, sometimes with (using password: NO), other times with (using password: YES)
Reading some posts, I tried all the following manipulation :
kill mysqld and then run
mysqld with --skip-grant-tables
It works and I can log into mysql but any operation proposed to UPDATE the password for user root turns a QUERY OK with 0 rows modified. It should be normal I suppose, as I am not log with grant tables I have no access to user informations and privileges.
Note that when I run
SELECT user();
or
SELECT current_user();
I get root# with nothing following.
Re-installing the databases using the script mysql_install_db. It does not work as is saying that no host "Arduino" or "localhost"could be looked up with /usr/bin/resolveip (nota: no such thing in that folder)
using the --force option it works.
I tried what is exposed in the following post SOLVED - MySQL - Can't Log In - Access Denied - Brand New Installation (OpenWRT)
With the command line
mysqladmin -uroot password pwd
I ended with the same answer :
error: 'Access denied for user 'root'#'localhost' (using password:
NO)'
Could anybody help me or tell me what is the cleanest way to uninstall and fully reinstall MySQL on OpenWRT?
Thank you
Well, yeah...
mysqladmin -uroot password pwd
^--missing --
Since you don't specify the password option correctly, you're effectively passing NO password to mysqladmin, and it doesn't log you in.
Try
mysqladmin -u root -p pwd
mysqladmin --user=root --password=pwd
instead.

Unable to login to MySQL

I installed MySQL using the following command:
sudo apt-get install mysql-server mysql-client mysql-common
It asks me for a root password (On package configuration), I enter one and confirm it.
sudo /etc/init.d/mysql start
However when I try logging in to mysql with user root and password which I supplied in the previous step, it denies me access:
root#mbilwebh02:/etc# > mysql --user root --password
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES).
Another attempt that I made was to uninstall and reinstall mysql without supplying a password but that fails as well.
I then switched the user on the server to mysql
root#mbilwebh02:/etc# sudo -u mysql -s
root#mbilwebh02:/etc# sudo -u mysql -s
bash: /root/.bashrc: Permission denied
mysql#mbilwebh02:/etc$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
At this point I am able to only start and stop mysql. Any ideas where I might be going wrong?
[EDIT]
After searching a lot I found that one can log in to mysql using debian-sys-maint as user and password which is in the debian.cnf file. There was no 'root' user in the mysql database hence everything I tried denied me access.
I do not know if this is a safe way to do it though.
Taken from: http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
Stop mysqld and restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.
Connect to the mysqld server with this command:
shell> mysql
Issue the following statements in the mysql client. Replace the password with the password that you want to use.
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
-> WHERE User='root';
mysql> FLUSH PRIVILEGES;
The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
You should now be able to connect to the MySQL server as root using the new password. Stop the server, then restart it normally (without the --skip-grant-tables and --skip-networking options).

MYSQL error: 1045 (28000): Access denied for user 'root'#'localhost'

When I try to connect to the sql server and enter the following in command prompt:
shell> mysql --user=username--password=password db_name
I get error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: Y
ES)
What does this error mean?
Looks like a space is missing between username and --password
If you don't know the root password, with Debian or Ubuntu, there is an easy way to reset it :
First, get the exact version of your server using
sudo dpkg --get-selections | grep 'mysql-server-'
Then, just use sudo dpkg-reconfigure mysql-server-5.x
(btw, replace 5.x with you real version number)
On a fresh install, the default root password is blank, so should be able to log in using just
mysql -u root
You should obviously add a root password after installation
mysqladmin -u root password [newpassword]
In most cases, you should also set up dedicated accounts with limited rights before working with a DB.
On Windows -
Search for services
Stop the service named MySQL[#] (in my case it was MySQL80).
Start the service again.
Open Command Prompt and type:
mysql [database name] -u [user name] -p
It worked for me when no other solutions worked. Hope this solves your issue as well.
It means your password is wrong or the account "root" has no access to the database on host "localhost".
Look at the right side bar. There are multiple questions equivalent to yours.

error 1045 (28000) access denied for user 'root'#'localhost' (using password: YES)

Please forgive me for being a complete beginner:
I am trying to log into my very first mySQL database that I installed using easyPHP on my windows machine, using the cmd line. I am going to the \mysql\bin and entering the command:
mysql -u root
in order to log in, but I am getting the following message:
error 1045 (28000) access denied for user 'root'#'localhost' (using password: YES)
Why is it using the password "YES"? Shouldn't there be no password at all? Do I need to restart mySQL or something? If so, how do I do that? If it's relevant, I did try to create the database using phpmyadmin, but had a few problems entering columns and decided I'd be better off working from the command line so I could learn all the commands as I went along.
Please keep in mind that this is my first time ever trying to work with a database, so be kind to me!
To have mysql asking you for a password, you also need to specify the -p-option:
mysql -u root -p
When logging into MYSQL using the command line, you also have to specify the password if any. Your error message is telling you that the user "root" has a password attached to it. Not necessarily that the password is "YES" when you were installing easyPHP, it should have either provided you with a default password or allowed you to enter a password of your choosing.
According to the documentation of easyPHP:
[v1.6] My scripts worked perfectly with 1.5 but now I get this error : Warning: Forbidden access for user: 'user#localhost' (password: YES) when I want to connect to MySql.
Only the root user (without password) has the rights to connect to the database. Either modify your scripts to use it, or add the user you need (phpMyAdmin/users and privileges: See phpMyAdmin's documentation for more information).
mysql -u root -p
Now if you changed your root user password, you will need to specify that when prompted. Otherwise simply hit <Enter> on your keyboard.
If you FORGOT the password to root, and have changed it, you will have to subsequently reinstall easyPHP.
agk-hp:~/$mysql
ERROR 1045 (28000): Access denied for user 'greg'#'localhost' (using password: NO)
agk-hp:~/$sudo cat /etc/mysql/debian.cnf|grep password
password = t7753my3D2x4yfQm
agk-hp:~/$mysql -u debian-sys-maint -p
Enter password: {t7753my3D2x4yfQm}
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql> use mysql;
mysql> grant all privileges on *.* to 'root'#'localhost';
mysql> grant all privileges on *.* to 'greg'#'localhost';
agk-hp:~/$mysql
mysql>
A modification for mysql- 5.7.10 on mac mac el capitan
sudo /usr/local/mysql/support-files/mysql.server stop
sudo mysqld_safe --skip-grant-tables
Now open new window/tab on terminal and type
"mysql -u root"
use mysql
update user set authentication_string=password('yourpassword') where user='root';