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?
Am using Ubuntu-16.04 : installed mysql - 5.7. I Had the same issue : Login denied for root user.
Tried the below steps:
1.
dpkg --get-selections | grep mysql
(to get the version of mysql).2.
dpkg-reconfigure mysql-server-5.7
3.
mysql -u root -p
Without -p that doesn't prompt you to ask password. Once you are in, you can create a user with a password by following steps :
CREATE USER 'your_new_username'@'your-hostname' IDENTIFIED BY 'your-password';
GRANT ALL PRIVILEGES ON *.* to 'your_new_username'@'your-hostname' WITH GRANT OPTION;
Exit from the root and login from the you gave above.
mysql -u <your_new_username> -p
For some reason still just typing mysql does not work. AT ALL. I suggest to make it a habit to use mysql -u -p.
In Ubuntu 16.04 (MySQL version 5.7.13) I was able to resolve the problem with the steps below:
Follow the instructions from the in section B.5.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems MySQL 5.7 reference manual
When I tried #sudo mysqld_safe --init-file=/home/me/mysql-init & it failed. The error was in /var/log/mysql/error.log
2016-08-10T11:41:20.421946Z 0 [Note] Execution of init_file '/home/me/mysql/mysql-init' started. 2016-08-10T11:41:20.422070Z 0 [ERROR] /usr/sbin/mysqld: File '/home/me/mysql/mysql-init' not found (Errcode: 13 - Permission denied) 2016-08-10T11:41:20.422096Z 0 [ERROR] Aborting
The file permission of mysql-init was not the problem, need to edit apparmor permission
Edit by #sudo vi /etc/apparmor.d/usr.sbin.mysqld
Do #sudo /etc/init.d/apparmor reload
Start mysqld_safe again try step 2 above. Check /var/log/mysql/error.log make sure there is no error and the mysqld is successfully started
Run #mysql -u root -p
Enter password:
Enter the password that you specified in mysql-init. You should be able to log in as root now.
Shutdown mysqld_safe by #sudo mysqladmin -u root -p shutdown
Start mysqld normal way by #sudo systemctl start mysql
Please read the official documentation: Mysql: How to Reset the Root Password
If you have access to terminal:
MySQL 5.7.6 and later:
MySQL 5.7.5 and earlier:
At the initial start up of the server the following happens, given that the data directory of the server is empty:
To reveal it, use the following command:
Change the root password as soon as possible by logging in with the generated temporary password and set a custom password for the superuser account:
I know this an old Question but i feel this might help someone. I was recently faced with the same problem but in my case, i remember my password quite alright but it kept on giving me the same error. I tried so many solutions but still none helped then i tried this
after which it asks you for a pass word like this
and then i typed in the password i used. That's all
I am using mysql-5.7.12-osx10.11-x86_64.dmg in Mac OSX
The installation process automatically sets up a temporary password for root user. You should save the password. The password can not be recovered.
Follow the instruction
cd /usr/local/mysql/bin/
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('{YOUR_PASSWORD}');
If you wish to set your password: "root" then the command would be,SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
exit
./mysql -u root -p
For convenience, you should add
"/usr/local/mysql/bin"
to your PATHNow from anywhere you can type
./mysql -u root -p
and then type the password and you will get mysql> prompt.Hope it helps.