0

When I installed mysql, I didn't write down the mysql root user password. I can get to the mysql prompt with just sudo mysql. However, mysql -u root -p does not work with the system's root password. I need to run a script, automysqlbackup, and it uses mysql -u root -p to login to mysql and create the backups.

There are a lot of pages on the Internet for resetting the mysql root password, but I am worried that I will lose the ability to use sudo mysql, and will have to always use mysql -u -p if I reset the root password for mysql.

Is there a way to find out what user/password mysql is using for sudo mysql? Will I trash the sudo mysql command if I change the mysql root password?

Thanks!

2
  • 2
    Default won't have a root password. Default in 20.04 and later is user socket level trust, so sudo mysql executes as the root user and thereby local-auths from the user level with the socket. You'd have to change the passwords, and then use sudo mysql -u root- p and then provide the password every time for the root user in MySQL
    – Thomas Ward
    Jan 27, 2023 at 16:55
  • Thanks for the clarification! In order to save the sudo mysql option without typing the password, I just created another user backup-mysql with a password, granted all privileges on all databases, and use that user and password for the backup script. Jan 27, 2023 at 18:15

0

You must log in to answer this question.

Browse other questions tagged .