CentOS6 Hortonworks Sandbox中mysqld状态显示已停止但实际运行
Hey there, let's unpack this odd behavior you're seeing—this is a classic quirk with custom sandbox setups like Hortonworks' CentOS 6 image, so let's walk through what's happening and how to fix it.
First, Let's Recap Your Exact Scenario (To Make Sure We're On The Same Page)
Here's what you ran, and the confusing results:
# Stop MySQL and confirm it's down (works as expected) [root@sandbox-hdp ~]# service mysqld stop [root@sandbox-hdp ~]# service mysqld status mysqld is stopped # Start MySQL, get a success message... but status says it's stopped? [root@sandbox-hdp ~]# service mysqld start Starting mysqld: [ OK ] [root@sandbox-hdp ~]# service mysqld status mysqld is stopped # But wait—you can still log into MySQL just fine! [root@sandbox-hdp ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.27 MySQL Community Server (GPL)
What's Actually Going On Here?
This almost always boils down to a PID file mismatch. Here's the breakdown:
- The CentOS 6
mysqldservice script checks a hardcoded path (usually/var/run/mysqld/mysqld.pid) to find the process ID (PID) of the running MySQL daemon. If it can't find this file, it assumes mysqld isn't running. - But Hortonworks Sandbox tweaks MySQL's configuration to store the PID file in a different location (like
/var/lib/mysql/sandbox-hdp.pid) to fit their sandbox setup. - So the service script is looking in the wrong place, spitting out that "stopped" message, even though MySQL is happily running in the background.
Step-by-Step Fixes to Get the Status Working Correctly
1. First, Find Where MySQL Is Actually Storing Its PID File
Log into MySQL and run this query to get the real PID file path:
SHOW VARIABLES LIKE 'pid_file';
You'll get output like this (the path will be specific to your sandbox):
+---------------+-----------------------------------+ | Variable_name | Value | +---------------+-----------------------------------+ | pid_file | /var/lib/mysql/sandbox-hdp.pid | +---------------+-----------------------------------+
Jot down that Value path—we'll need it next.
2. Update the mysqld Service Script to Use the Correct PID Path
Open the service script in your editor of choice (I'll use vi here):
vi /etc/init.d/mysqld
Search for the line that defines pidfile—it'll look something like this:
pidfile=/var/run/mysqld/mysqld.pid
Replace that path with the one you found in MySQL. For example:
pidfile=/var/lib/mysql/sandbox-hdp.pid
Save and exit the editor, then reload the init script configuration to apply the change:
chkconfig --add mysqld
3. Verify the Fix Works
Now let's test it out:
# Stop MySQL first [root@sandbox-hdp ~]# service mysqld stop # Start it back up [root@sandbox-hdp ~]# service mysqld start Starting mysqld: [ OK ] # Check status—this should now show it's running! [root@sandbox-hdp ~]# service mysqld status mysqld (pid 1456) is running...
And of course, confirm you can still log into MySQL without issues.
Quick Alternative Check (If You Don't Want to Edit the Script Right Now)
If you just need to confirm MySQL is running without fixing the service script, use the ps command to look for the mysqld process directly:
ps aux | grep mysqld | grep -v grep
If you see output with a mysqld process, that's proof it's running—ignoring the misleading service status message.
内容的提问来源于stack exchange,提问作者Erkan Şirin

