Objective
The objective is to reset lost root MySQL password on Ubuntu 18.04 Bionic Beaver Linux
Operating System and Software Versions
Privileged access to your Ubuntu System as root or via sudo command is required.
Difficulty
EASY
Conventions
Instructions
Reset by using mysql_secure_installation
The simplest approach to reset MySQL database root password is to execute mysql_secure_installation program and when prompted entering your new root MySQL password:
Reset by using skip-grant-tables
If from some reason the above method fails follow the step below to use --skip-grant-tables to reset MySQL root password.
Let's start by stopping the currently running MySQL database: $ sudo service mysql stop
Next, create a /var/run/mysqld directory to be used by MySQL process to store and access socket file:
Once ready manually start MySQL with the following linux command and options:
Confirm that the process is running as expected:
The objective is to reset lost root MySQL password on Ubuntu 18.04 Bionic Beaver Linux
Operating System and Software Versions
- Operating System: - Ubuntu 18.04 Bionic Beaver
- Software: - mysql Ver 14.14 or higher
Privileged access to your Ubuntu System as root or via sudo command is required.
Difficulty
EASY
Conventions
- # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
- $ - requires given linux commands to be executed as a regular non-privileged user
Instructions
Reset by using mysql_secure_installation
The simplest approach to reset MySQL database root password is to execute mysql_secure_installation program and when prompted entering your new root MySQL password:
PHP:
$ sudo mysql_secure_installation
....
Please set the password for root here.
New password:
Re-enter new password:
Reset by using skip-grant-tables
If from some reason the above method fails follow the step below to use --skip-grant-tables to reset MySQL root password.
Let's start by stopping the currently running MySQL database: $ sudo service mysql stop
Next, create a /var/run/mysqld directory to be used by MySQL process to store and access socket file:
Bash:
$ sudo mkdir -p /var/run/mysqld
$ sudo chown mysql:mysql /var/run/mysqld
Once ready manually start MySQL with the following linux command and options:
Bash:
$ sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
$ [1] 2708
Confirm that the process is running as expected:
Bash:
$ jobs
[1]+ Running sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &