I installed mysql on ubuntu server and did not specify password. When I do
mysql -u root -p
it prompts for password and without providing any input I just hit enter and it works.
Now I need to perform some operation on the database using cron job. My cron job does not work because mysql prompts for a password. I tried doing
mysql -u root -p'' my_database
but that did not work either.
Any suggestion?
Recover MySQL root passwordStart the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for a password. Connect to the MySQL server as the root user. Set a new root password. Exit and restart the MySQL server.
In the mysql client, tell the server to reload the grant tables so that account-management statements work: mysql> FLUSH PRIVILEGES; Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use.
The default user for MySQL is root and by default it has no password.
Go like this mysql -u root --password="" dbname
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With