Access Denied to user root localhost while using mysql

0 votes

Hi, I am new t linux and this the first time for me working with mysql. So I've been following this tutorial to set up mySQL on my machine. These are the following commands I've used so far:

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

After this, when I try and run this:

me@ubuntu:~/Desktop/iPDC-v1.3.1/DBServer-1.1$ mysql -uroot -proot <"Db.sql"

I get this error.

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

What am I doing wrong here?

May 13, 2019 in Linux Administration by Atul
• 10,240 points

1 answer to this question.

0 votes

For MySQL versions < 5.7:

the default root password should be nothing so just tap enter after:

mysql -u root

You should obviously change your root password after installation

To set a new password do:

mysqladmin -u root password [newpassword]

This should be enough to set you up for the DB Operations

For versions that came after 5.7:

So when you initialize the server, the data directory of the server is empty:

  • The server is initialized.
  • SSL certificate and key files are generated in the data directory.
  • The validate_password plugin is installed and enabled.
  • The superuser account 'root'@'localhost' is created. The password for the superuser is set and stored in the error log file.

This generates a temporary password. Use this command to show:

shell> sudo grep 'temporary password' /var/log/mysqld.log

Now change the root password, Use:

shell> mysql -uroot -p 

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass5!'; 
answered May 13, 2019 by DareDev
• 6,890 points

Related Questions In Linux Administration

0 votes
1 answer

error: Putty.exe has been denied access to IP

Hi@akhtar, The error may occur because of firewall. Your ...READ MORE

answered May 28, 2020 in Linux Administration by MD
• 95,440 points
0 votes
1 answer

How to create HTTP user using htpasswd command?

Hi@akhtar, Htpasswd command is available in the Linux ...READ MORE

answered Dec 2, 2020 in Linux Administration by MD
• 95,440 points
0 votes
0 answers

Send private message to Discord user using bash and linux AT command

I'm running a Discord bot written in ...READ MORE

Apr 25, 2022 in Linux Administration by Edureka
• 13,670 points
0 votes
1 answer

How to take input from user in bash script?

You can use if-else branch to check ...READ MORE

answered Jan 31, 2019 in Linux Administration by Omkar
• 69,230 points
0 votes
1 answer

Want a command to be executed in Salt only if a directory is empty

You should consider using this inside your ...READ MORE

answered Jun 12, 2018 in DevOps Tools by Damon Salvatore
• 5,980 points
0 votes
1 answer

Creating A New MySQL User In Amazon RDS Environment

AWS RDS security groups documentation (a common ...READ MORE

answered Jul 18, 2018 in AWS by Priyaj
• 58,090 points
0 votes
1 answer

Using conditional to execute a command in salt

You can use unless inside your state ...READ MORE

answered Jul 23, 2018 in Other DevOps Questions by DareDev
• 6,890 points
0 votes
1 answer

How to perform proxy http request using curl?

One of the ways is: export http_proxy=http://your.proxy.server:port/ Then you ...READ MORE

answered Mar 26, 2019 in Linux Administration by DareDev
• 6,890 points
0 votes
1 answer

How to find the group associated with a user in linux?

To list all the groups groups or to list ...READ MORE

answered Jun 21, 2019 in Linux Administration by DareDev
• 6,890 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP