Application Management

How can we help?

Guides and technical documentation for your Server4You dedicated server or VPS.

Change MySQL Root Password

This guide explains how to reset a lost or forgotten root password for MySQL or MariaDB on your Linux server. You temporarily start the database without permission checks, set a new password and then restart the service normally.

Step 1: Restart MySQL in Safe Mode

Stop the running MySQL service and restart it with the --skip-grant-tables option. This disables permission checks and allows you to log in without a password; --skip-networking blocks network access in the meantime. With MariaDB on Debian or Ubuntu, the service is called mariadb — and root can often log in as the system user root via mysql without a password, so try this first.

Stop MySQL Service
systemctl stop mysql # MariaDB: systemctl stop mariadb
Start MySQL in Safe Mode
mkdir -p /run/mysqld && chown mysql:mysql /run/mysqld mysqld_safe --skip-grant-tables --skip-networking &

The first line creates the socket directory, which is removed when the service stops. The & at the end runs the process in the background so you can continue using the terminal.

Step 2: Connect to MySQL

Once the server is running in safe mode, connect as the root user — no password is required at this point.

Connect as Root
mysql -u root

Step 3: Set the New Password

Run the following SQL commands to update the root password. FLUSH PRIVILEGES reloads the permission tables first — without it, ALTER USER fails in safe mode. Replace MyNewPass with your own strong password.

The commands below apply to MySQL 5.7.6+ and MariaDB 10.1.20+. Older versions used UPDATE mysql.user SET Password=..., which is deprecated and should no longer be used.

Change Password & Apply
FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'; exit;

Step 4: Restart MySQL Normally

Stop the manually started safe-mode process (you will be asked for the new password) and bring MySQL back up normally so that all security checks are re-enabled.

Stop Safe Mode Process
mysqladmin -u root -p shutdown
Start MySQL Service
systemctl start mysql # MariaDB: systemctl start mariadb

Your MySQL root password has now been changed and the server is running normally with all security checks active.

Further Documentation

For advanced MySQL configuration and administration, refer to the official documentation.