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.
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 restart3. 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-networking5. Restart MySQL service again
# service mysqld restartSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
