4

I've just installed MySQL server with no password on root account. I was prompted to enter root password 3 times and I left it blank all three times because I don't want to use password. But now it seems to me that may not be such a great idea.

I try to connect from Workbench (with now password entered) and I get error: Access denied for user 'root'@'localhost'. Why if there is no password??

I realize now, that if I only have had provided some dummy password on installation I would have no problems no, so I try to set it by typing: mysqladmin -u root -p password; enter blank password, and again, get the following:

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost'

If I just type "mysql" into console I get:

Access denied for user 'me'@'localhost' (using password: NO)

If I can have root account without password, and if I won't have much problems in that case, than I'd like to leave it without pass, but if that isn't good, than please tell me how set password. And if it's good to leave it without password then please tell me how to connect without pass :)

EDIT: Linux distro: Mint Cinnamon 64-bit; MySQL version: 5.7

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Scarass
  • 223

2 Answers2

7

By default Debian/Ubuntu/Mint has a user with administrative accesses, namely used to shutdown MySQL, called debian-sys-maint.

Go to the file /etc/mysql/debian.cnf which has as the format:

[client]
host     = localhost
user     = debian-sys-maint
password = XXXXXXXX
socket   = /var/run/mysqld/mysqld.sock 

Take from there the password, that is randomly generated when installing MySQL (e.g. it differs between servers);

And login into your MySQL with:

mysql -udebian-sys-maint -pXXXXXXXX

After that, you can change your root password.

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');

Be aware that this changed slightly in MySQL 5.7. Have a look at How to change MySQL 'root' password using MySQL v5.7?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
1

You should run :

# mysql_secure_installation

You can set a root password for fresh installation of mysql server.

supriady
  • 167
  • 1
    I enter that command, asks me for root password, I enter it, get access denied. The problem is, that after all this, I'm not really sure what is the root password. I tried entering blank, the one from /etc/mysql/debian.cnf – Scarass Dec 26 '16 at 11:38
  • and the one from /etc/mysql/debian.cnf and the one I tried to set in MySQL monitor – Scarass Dec 26 '16 at 11:39
  • The root password should be blank when you didnt set any root password yet on mysql-server. mysql_secure_installation helped you to set root password for new installation of mysql server. – supriady Dec 26 '16 at 14:05