Halaman

Jumat, 28 Februari 2020

MySQL Root Access


Step 1
Shut down Mysql. Try
sudo service mysql stop
or
sudo /etc/init.d/mysql stop
or looking up the PID and killing it. Make sure it's stopped via:
service mysql status



Step 2
Start MySQL in safe mode without a password:
mysqld_safe --skip-grant-tables --skip-networking &


If show this error please do : (^C to stop)
mkdir /var/run/mysqld
touch /var/run/mysqld/mysqld.sock
chown mysql:mysql /var/run/mysqld
and do again
mysqld_safe --skip-grant-tables --skip-networking &

Step 3
In a new terminal, connect to MySQL server with the mysql client. No password is neccessary. Execute the following steps:
mysql -u root
use mysql;
UPDATE user SET authentication_string=PASSWORD("securepassword") where User='root';
UPDATE user SET plugin="mysql_native_password";
FLUSH PRIVILEGES;
quit;

Brief explanation: The second line is where you set your password. One difference between MySQL 5.6 or older, and the latest 5.7+ is the column name switch from PASSWORD to AUTHENTICATION_STRING. Older tutorials use the former.
If you miss the third 'set plugin' statement, you'll successfully update your password but still won't be able to connect to your server. My system, for example, had the plugin value set to 'auth socket.' Even with the right login details, my server threw errors about my missing socket, and I needed to shut down, restart in safe mode, and switch both values again.
Finally, the 'flush privileges' command reloads the server's in-memory copy of the grant tables. Modifying the user table with UPDATE doesn't load the changes into the tables immediately, unlike the higher-level GRANT or SET commands.

Step 4
Stop your safe mysqld, and start the mysql server normally.
ps aux | grep mysql
kill (mysqlPID)
do for all mysql PID process
service mysql start
You should be able to connect with your new password via

mysql -u root -p

Enjoy your new database access!

2 komentar:

  1. Assalamualaikum.. apakah boleh mints kontak bapak yg bisa saya hubungi,
    email atau telegram. ada beberapa hal yg saya mau tanyakan. hehe

    BalasHapus