Score:0

What is the user/password for `sudo mysql` on Ubuntu 20.04?

kz flag

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!

ru flag
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
kz flag
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.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.