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
How to Modify MySQL Startup Script, Reset Root Password, and Restore Settings on Linux

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
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
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.