Skip to content
How to Modify MySQL Startup Script, Reset Root Password, and Restore Settings on Linux
Databases 2 min read

How to Modify MySQL Startup Script, Reset Root Password, and Restore Settings on Linux

This guide shows how to edit the MySQL server startup script to add skip-grant and skip-networking options, restart the MySQL service, change the root user password, and then revert the script changes, providing step‑by‑step commands and screenshots for each operation.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations

1. Modify MySQL server script

~]# vi /etc/rc.d/init.d/mysqld
# locate $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 & wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?
# add --skip-grant --skip-networking after this line

$bindir/mysqld_safe --datadir="$datadir" --skip-grant --skip-networking --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?

2. Restart MySQL service

# service mysqld restart

3. Update or modify MySQL root user password

~]# mysql> USER mysql
~]# mysql> UPDATE user SET password=PASSWORD('mypasshao') WHERE user='root';

4. Remove --skip-grant and --skip-networking from MySQL startup script

# vi /etc/rc.d/init.d/mysqld
# find the following line:
$bindir/mysqld_safe --datadir="$datadir" --skip-grant --skip-networking --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?
# delete --skip-grant and --skip-networking

5. Restart MySQL service again

# service mysqld restart
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxMySQLdatabase administrationRoot Passwordservice restartstartup script
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.