MySQL login failed with new Dataproc image?

Viewed 46

I used mysql client to log into mysql server from the master node of dataproc and it is failing now.

Using the following command

mysql -uroot -p<password> 

I am now seeing the following error message.

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
1 Answers

With the release of Dataproc 1.5.72 and 2.0.46 onwards, the default mysql root password has been modified. The password can be read by the OS level root user or someone with sudoer access. The password is now a random generated value and can be found in /etc/mysql/my.cnf

The change affect users when

  • trying to log into mysql using the mysql client using root acct
  • using your own dataproc init scripts that require mysql root user

You can use the following snippet

mysqlroot_password="$(sudo grep 'password=' /etc/mysql/my.cnf | sed 's/^.*=//')"
echo $mysqlroot_password

Three options to logging into mysql

sudo su
mysql $(cat /etc/mysql/my.cnf | grep password | cut -f2 -d=)
mysql -u root -p$(sudo cat /etc/mysql/my.cnf | grep password | cut -f2 -d=)

If you need to use the password multiple times in your script.

mysqlroot_password="$(sudo grep 'password=' /etc/mysql/my.cnf | sed 's/^.*=//')"
mysql -u root -p${mysqlroot_password}
Related