The MySQL root password allows the root user full access to the MySQL database. If you do not remember the root password of the mysql database, you can reset it as follows.
It is necessary to connect with root in Linux environments and with administrator in windows environments to perform these operations.
Reset MySQL root Password
Step 1: Stop MySQL Service
Stop MySQL Server in Ubuntu or Debian:
1 | /etc/init.d/mysql stop |
Stop MySQL Server in CentOS, Fedora, Red Hat Enterprise Linux or Oracle Enterprise Linux:
1 | /etc/init.d/mysqld stop |
Step 2:Start MySQL Without Password
1 | mysqld_safe --skip-grant-tables & |
1 | mysql -uroot |
Step 3: Create New MySQL root Password
From mysql cli:
1 | use mysql; |
1 | update user set password=PASSWORD("newpassword") where User='root'; |
1 | flush privileges; |
1 | quit |
Step 4: Restart MySQL Service
1 | /etc/init.d/mysql stop |
1 | /etc/init.d/mysql start |
Step 5: Connect To MySQL With New Password
1 | mysql -u root -p |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | root@debian:~# /etc/init.d/mysql stop [ ok ] Stopping mysql (via systemctl): mysql.service. root@debian:~# mysqld_safe --skip-grant-tables & [1] 30091 root@debian:~# 180922 22:50:31 mysqld_safe Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect. 180922 22:50:31 mysqld_safe Logging to '/var/log/mysql/error.log'. 180922 22:50:31 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql root@debian:~# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.55-0+deb8u1 (Debian) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set password=PASSWORD("yenisifre") where User='root'; Query OK, 0 rows affected (0.00 sec) Rows matched: 4 Changed: 0 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye root@debian:~# /etc/init.d/mysql stop [ ok ] Stopping mysql (via systemctl): mysql.service. root@debian:~# /etc/init.d/mysql start [ ok ] Starting mysql (via systemctl): mysql.service. root@debian:~# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.5.55-0+deb8u1 (Debian) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> |