I am an electrical engineering who mainly play around with power system instead of programming. Recently, I have been following a manual to install a software suite on Ubuntu. I have no knowledge on mySQL
at all, actually. I have done the following installations on my Ubuntu.
sudo apt-get update
sudo apt-get install mysql-server-5.5
sudo apt-get install mysql-client-5.5
sudo apt-get install mysql-common
sudo apt-get install glade
sudo apt-get install ntp
Then I do
me@ubuntu:~/Desktop/iPDC-v1.3.1/DBServer-1.1$ mysql -uroot -proot <"Db.sql"
I ended up with the following error message.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
How may I fix it and continue?
BY default password will be null, so you have to change password by doing below steps.
connect to mysql
root# mysql
Use mysql
mysql> update user set password=PASSWORD('root') where User='root'; Finally, reload the privileges:
mysql> flush privileges; mysql> quit
You have to reset the password! steps for mac osx(tested and working) and ubuntu
Stop MySQL using
or
Start it in safe mode:
(above line is the whole command)
This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
As per @IberoMedia's comment, for newer versions of MySQL, the field is called
authentication_string
:Start MySQL using:
or
your new password is 'password'.
The answer may sound silly, but after wasting hours of time, this is how I got it to work
I got the error message
Even though I was typing the correct password(the temporary password you get when you first install mysql)
I got it right when I typed in the password when the password prompt was blinking
It happens when your password is missing.
Steps to change password when you have forgotten:
Stop MySQL Server (on Linux):
Start the database without loading the grant tables or enabling networking:
The ampersand at the end of this command will make this process run in the
background so you can continue to use your terminal and run #mysql -u root, it will not ask for password.
If you get error like as below:
2018-02-12T08:57:39.826071Z mysqld_safe Directory '/var/run/mysqld' for UNIX
socket file don't exists. mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2) [1]+ Exit 1
Make MySQL service directory.
Give MySQL user permission to write to the service directory.
Run the same command in step 2 to run mysql in background.
Run mysql -u root you will get mysql console without entering password.
Run these commands
For MySQL 5.7.6 and newer
For MySQL 5.7.5 and older
If the ALTER USER command doesn't work use:
Now exit
To stop instance started manually
Restart mysql
Just one line and it solved my issue.
if the problem still exists try to force changing the pass
Setup new MySQL root user password
Stop MySQL Server:
Start MySQL server and test it: