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?
Note: For MySQL 5.7+ please see answer from @Lahiru to this question. That contains more current information.
For MySQL < 5.7:
The default root password is blank (i.e. empty string) not
root
. So you can just login as:You should obviously change your root password after installation
In most cases you should also set up individual user accounts before working extensively with the DB as well.
I was able to solve this problem by executing this statement
Which will change the root password.
I came across this very annoying problem and found many answers that did not work. The best solution I came across was to completely uninstall mysql and re-install it. On re-install you set a root password and this fixed the problem.
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.5 mysql-client-core-5.5 sudo rm -rf /etc/mysql /var/lib/mysql sudo apt-get autoremove sudo apt-get autoclean
I found this code elsewhere so I take no credit for it. But it works. To install mysql after uninstalling it I think digital ocean has a good tutorial on it. Checkout my gist for this.
https://gist.github.com/JamesDaniel/c02ef210c17c1dec82fc973cac484096
if the problem still exists try to force changing the pass
Stop MySQL Server (on Linux):
Stop MySQL Server (on Mac OS X):
Start mysqld_safe daemon with --skip-grant-tables
Setup new MySQL root user password
Stop MySQL Server (on Linux):
Stop MySQL Server (on Mac OS X):
Start MySQL server service and test to login by root:
In recent MySQL versions there is no
password
inmysql.user
table.So you need to execute
ALTER USER
. Put this one line command into the file.And execute it as init file (as root or mysql user)
MySQL server need to be stopped to start
mysqld_safe
.Also, there may be a problem with apparmor permissions to load this init file. Read more here https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql
If you haven't set password yet, then run
mysql -uroot
, it works for me.