rahnev

Well-Known Member
Jul 6, 2016
62
7
58
Bulgaria
cPanel Access Level
Root Administrator
Is there any way to view the current MySQL password on cPanel DNSOnly installation? I can login to it using mysql command but want to view the current one. There is no way to change it via Web UI.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
Hello,

The MySQL root password is stored in the /root/.my.cnf file by default.

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
Hello,

Is it possible it exists at another location? You can try finding it with a command such as:

Code:
find / -name ".my.cnf"
If it doesn't exist, you can manually create this file in the /root directory with root ownership and 0600 permissions. Then, ensure the contents look like this:

Code:
[client]
password=MySQLRootPasswordHere
user=root
Once this file is setup, you can follow the instructions to reset the MySQL root password from the top answer on a third-party URL like this:

Change mysql root password on Centos7

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
Hello @ronaldst,

Could you open a support ticket using the link in my signature so we can take a closer look?

Thank you.
 

ronaldst

Well-Known Member
Feb 22, 2016
85
16
8
Norway
cPanel Access Level
Root Administrator
I found another source of information and this lead me to a working solution.

The easiest way to do this:

1. edit /etc/my.cnf, add the following
Code:
[mysqld]
skip-grant-tables
2. restart mysql
Code:
service mysql restart
3. Run the following
Code:
mysql -u root
use mysql
UPDATE mysql.user SET Password=PASSWORD('YourPassword') WHERE USER='root' AND Host='localhost';
FLUSH PRIVILEGES;
quit
4. edit /etc/my.cnf and remove the variable added in step 1 (skip-grant-tables)

5. restart mysql
Code:
service mysql restart
6. test login with new password
Code:
mysql -u root -h localhost -p
Password
7. Create a /root/.my.cnf
Code:
[client]
password=YourPassword
user=root
8. Change file permissions of .my.cnf
Code:
chmod 0600 .my.cnf
8. Test .my.cnf by logging into MySQL again
Code:
mysql -u root

This worked for me running MySQL 5.6. on cPanel DNSOnly server.
 
Last edited:
  • Like
Reactions: cPanelMichael