Have you forgotten your MySQL root password? (I know, i know πππ it's a secret.)
If you do, and trying to find out how to do it, then you are in the right path my friend.
Let's start and let's code pare.
Quick Note:
if you're doing this in your live server with a live users then congratulations you're a PRO developer. π π π
If ever you don't have a choice, make sure to change it late night or when there is not much traffic in your server.
STEP 1
First thing we need to do is login in your server and to stop MySQL service.
if you logged in as root user then type this code
Incase you're not a root user but have privilege as a root, then just add sudo
in the beginning of the command.
Once you run this code, it will stop your mysql services and no one can connect to your database temporary.
( Make sure to notify your co-developer and the other teams involve or else you will receive a new Ticket Error π )
STEP 2
We need to start our mysql in a safe mode. What is mysqld_safe command means?
mysqld_safe is the recommended way to start a mysqld server on Unix. mysqld_safe adds some safety features such as restarting the server when an error occurs and logging runtime information to an error log. A description of error logging is given later in this section.
Run this code below, when running mysqld_safe with --skip-grant-tables
it enables anyone to connect without a password and with all privileges. Together with the ampersand "&" to run the command in the background.
STEP 3
We're almost there pare, just keep going.
Login in our mysql by running this command, you should see the mysql monitor welcome screen.
STEP 4
In this step, we will change the password of your mysql root user.
Type this code, to use mysql table and Press enter
Then the code to change your root password is the command below. Make sure to change the "EnterYourSuperCoolPasswordHere" before running it.
Take note, the authentication_string is for mysql 5.7 up version.. incase you have a lower version of mysql you can use password column instead.
Reload the grant tables to take effect using the command below.
Then exit from mysql command window using
STEP 5
Start your mysql server
And login in your mysql as root user using your new password.
If everything works, then you will see a welcome message in mysql monitor command screen.
COMMON ERRORS
1). Access denied; you need (at least one of) the SHOW DATABASES privilege(s) for this operation.
SOLUTION: Login as mysql root then type this command:
2). mysqld_safe Directory β/var/run/mysqldβ for UNIX socket file donβt exists.
SOLUTION:
Then try to stop or start again mysql.
3) ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded. Basically we need to set the authorization plugin back to mysql_native_password.
SOLUTION: Login as mysql root then type this command:
4) ERROR 1054 (42S22): Unknown column βpasswordβ in βfield listβ
SOLUTION:
It means you're using a low version of code for mysql 5.6 below. password column was removed from mysql 5.7 above, As i mention in the tutorial above you need to use authentication_string
Voila
I hope i help you solving your problem. Let me know incase you encounter a different error.
Thanks pare. π π π
Next Featured
Explore our security tips for safety server and process. Explore our security tips for safety server and process
Voila!!!
I hope you enjoy our tutorial, Let me know incase you encounter any error I would love to answer that. Don't forget to subscribe to my Youtube Channel at Let's Code Pare - Youtube Channel