55

I'm trying to install queXS cati app on my Ubuntu desktop and I installed MySQL server and PHP 5 and I cannot login into MySQL server as root without password:

mysql -u root 

it says

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

But it's okay when I enter mysql -u root -p

I can't figure out what the problem is.

1
  • 8
    Try this: mysql -u root -p mysql Enter password: and you will get: mysql>
    – user273774
    Apr 24, 2014 at 18:47

3 Answers 3

54

Add switch -p for password based login:

mysql -u root -p

That is the normal behaviour. You set a root password for your database so from now on you can't access it without password. That is why it reports:

Access denied for user 'root@localhost' (using password: no )

Obviously when you give the password with the -p switch you succeed.

6

In simple words your "root" session does not know the password of the mysql root user.

If you want to make it easier to access your mysql, create a file .my.cnf in /root/ with these lines:

[mysqladmin]
 user = root
 password = mysqlrootpassword
[mysql]
 user = root
 password = mysqlrootpassword
[mysqldump]
 user = root
 password = mysqlrootpassword

where of course mysqlrootpassword is your password for mysql's root password. When you execute mysql it uses this password.

Attend to the safety of this file - give it secure rights, so that nobody on your server can read it!

2
  • 1
    It's bad to encourage others to put root passwords plaintext on disk. By deduction, that badness property propagates to the person doing it. Dec 31, 2015 at 11:49
  • During installation mysql root user's temporary password is set . sudo grep 'temporary password' /var/log/mysqld.log
    – suyash
    May 13, 2017 at 13:49
-1

Login to webmin and under servers, access the mySQLdatabase server.You will then be able to set the (user) password provided you have:

mysql -u (**user**) -p < /usr/share/doc/rsyslog-mysql-5.8.10/createDB.sql.

The web gui is easy but to be secure use the terminal.

cheers.

1
  • do not exists /usr/share/doc/rsyslog-mysql-5.8.10/createDB.sql. Sep 14, 2015 at 15:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.