LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (https://www.linuxquestions.org/questions/red-hat-31/)
-   -   MySQL cannot start except manually as root (https://www.linuxquestions.org/questions/red-hat-31/mysql-cannot-start-except-manually-as-root-826558/)

yjd 08-16-2010 11:13 AM

MySQL cannot start except manually as root
 
Hello,

I'm new to Red Hat and Linux in general. I have setup the Red Hat system and installed MySQL through the Add / Remove Program. I have RHEL 5.4.

When MySQL is being started manually it is being started as root. However, when MySQL is being started using the services command it is started as the user MySQL and it doesn't work.

How can I start MySQL service as root?
Or is there another way to fix that issue.

Let me know if you need more information (giving details on how to get it would be nice too).


Thank you,
Yael

quanta 08-16-2010 11:48 AM

In default, init script in /etc/init.d calls mysqld_safe run as root and mysqld_safe fork mysqld - a child process run as mysql user:
Code:

root      2657    1  0 Jun13 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --user=mysql
mysql    2707  2657  0 Jun13 ?        02:31:06 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock

Post up the output when you manually start MySQL and service command (I don't understand what you mean) and give us the output of ps -ef | grep mysqld after that. Also post the content of init script (/etc/init.d/mysqld)

johnshen64 08-16-2010 11:53 AM

make sure your datadir (normally /var/lib/mysql) and everything under it are owned by mysql. do a chown -R mysql.mysql /var/lib/mysql (or whatever your datadir is) to be sure, and then retry to start the service.

chickenjoy 08-16-2010 12:18 PM

well for security reasons; mysqld process should never be run as root since some internal commands can wright directly to the file system and it inherits the permissions of who ever started it. In short: started by root = mysql has access to the whole system.

yjd 08-16-2010 02:27 PM

Quanta, here is the result when I start mysql manualy (I'm already in root):

Code:

[amrita@AMRStag ~]$ su -
Password:
[root@AMRStag ~]# /sbin/service mysqld start
touch: cannot touch `/var/lib/mysql/mysqld.log': Read-only file system
chown: changing ownership of `/var/lib/mysql/mysqld.log': Read-only file system
chmod: changing permissions of `/var/lib/mysql/mysqld.log': Read-only file system
chown: changing ownership of `/var/lib/mysql': Read-only file system
chmod: changing permissions of `/var/lib/mysql': Read-only file system
--datadir = /var/lib/mysql  --log-error= /var/lib/mysql/mysqld.log  --pid-file= /var/lib/mysql/mysqld.pid --socket=/var/lib/mysql/mysql.sock
Starting MySQL:                                            [  OK  ]
[root@AMRStag ~]# ps -ef | grep mysqld
root    26216    1  0 10:26 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --log-error=/var/lib/mysql/mysqld.log --pid-file=/var/lib/mysql/mysqld.pid --user=mysql
mysql    26278 26216  0 10:26 ?        00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock
root    27546 27357  0 13:20 pts/1    00:00:00 grep mysqld
[root@AMRStag ~]# cat /etc/init.d/mysqld
#!/bin/bash
#
# mysqld        This shell script takes care of starting and stopping
#              the MySQL subsystem (mysqld).
#
# chkconfig: - 64 36
# description:  MySQL database server.
# processname: mysqld
# config: /etc/my.cnf
# pidfile: /var/run/mysqld/mysqld.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network


prog="MySQL"

# extract value of a MySQL option from config files
# Usage: get_mysql_option SECTION VARNAME DEFAULT
# result is returned in $result
# We use my_print_defaults which prints all options from multiple files,
# with the more specific ones later; hence take the last match.
get_mysql_option(){
        result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
        if [ -z "$result" ]; then
            # not found, use default
            result="$3"
        fi
}

get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"
socketfile="$result"
get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"
errlogfile="$result"
get_mysql_option mysqld_safe pid-file "/var/run/mysqld/mysqld.pid"
mypidfile="$result"

start(){
        touch "$errlogfile"
        chown mysql:mysql "$errlogfile"
        chmod 0640 "$errlogfile"
        [ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
        if [ ! -d "$datadir/mysql" ] ; then
            action $"Initializing MySQL database: " /usr/bin/mysql_install_db --datadir="$datadir" --user=mysql
            ret=$?
            chown -R mysql:mysql "$datadir"
            if [ $ret -ne 0 ] ; then
                return $ret
            fi
        fi
        chown mysql:mysql "$datadir"
        chmod 0755 "$datadir"
        # Pass all the options determined above, to ensure consistent behavior.
        # In many cases mysqld_safe would arrive at the same conclusions anyway
        # but we need to be sure.
          echo "--datadir = $datadir  --log-error= $errlogfile  --pid-file= $mypidfile --socket=$socketfile"
        /usr/bin/mysqld_safe  --datadir="$datadir" --socket="$socketfile" \
                --log-error="$errlogfile" --pid-file="$mypidfile" \
                --user=mysql >/dev/null 2>&1 &
        ret=$?
        # Spin for a maximum of N seconds waiting for the server to come up.
        # Rather than assuming we know a valid username, accept an "access
        # denied" response as meaning the server is functioning.
        if [ $ret -eq 0 ]; then
            STARTTIMEOUT=30
            while [ $STARTTIMEOUT -gt 0 ]; do
                RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1` && break
                echo $RESPONSE
                echo "$RESPONSE" | grep -q "Access denied for user" && break
                sleep 1
                let STARTTIMEOUT=${STARTTIMEOUT}-1
            done
            if [ $STARTTIMEOUT -eq 0 ]; then
                    echo "Timeout error occurred trying to start MySQL Daemon."
                    action $"Starting $prog: " /bin/false
                    ret=1
            else
                    action $"Starting $prog: " /bin/true
            fi
        else
            action $"Starting $prog: " /bin/false
        fi
        [ $ret -eq 0 ] && touch /var/lock/subsys/mysqld
        return $ret
}

stop(){
        MYSQLPID=`cat "$mypidfile"  2>/dev/null `
        if [ -n "$MYSQLPID" ]; then
            /bin/kill "$MYSQLPID" >/dev/null 2>&1
            ret=$?
            if [ $ret -eq 0 ]; then
                STOPTIMEOUT=60
                while [ $STOPTIMEOUT -gt 0 ]; do
                    /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break
                    sleep 1
                    let STOPTIMEOUT=${STOPTIMEOUT}-1
                done
                if [ $STOPTIMEOUT -eq 0 ]; then
                    echo "Timeout error occurred trying to stop MySQL Daemon."
                    ret=1
                    action $"Stopping $prog: " /bin/false
                else
                    rm -f /var/lock/subsys/mysqld
                    rm -f "$socketfile"
                    action $"Stopping $prog: " /bin/true
                fi
            else
                action $"Stopping $prog: " /bin/false
            fi
        else
            ret=1
            action $"Stopping $prog: " /bin/false
        fi
        return $ret
}
 
restart(){
    stop
    start
}

condrestart(){
    [ -e /var/lock/subsys/mysqld ] && restart || :
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status mysqld
    ;;
  restart)
    restart
    ;;
  condrestart)
    condrestart
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|condrestart|restart}"
    exit 1
esac

exit $?
[root@AMRStag ~]#

johnshen64, when I do that command it returns nothing.

chickenjoy, thanks for the info.

The /var/lib/mysql is pointed to a LUN which is already mounted.
Do I need to setup something in /etc/fstab to give everyone read and write access to that LUN, could that be the problem?

Let me know if you need anything else.
Thanks,
Yael

quanta 08-16-2010 08:33 PM

Run the commands below and give us the output:
Code:

# ls -l /var/lib/mysql
# mount
# cat /etc/fstab


DrLove73 08-17-2010 01:49 AM

Most likely LUN is mounted with read-only permissions. Or there was problems with permissions and chown/chmod need to be applied upper in the tree with recursive option. Nice catch @quanta.

yjd 08-17-2010 08:10 AM

LUN permission could be the issue, what am I suppose to add in my fstab?

Here is what Quanta requested

Code:

[root@AMRStag ~]# ls -l /var/lib/mysql                                         
ls: reading directory /var/lib/mysql: Input/output error                       
total 0                                                                       
[root@AMRStag ~]# mount                                                       
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)                           
proc on /proc type proc (rw)                                                   
sysfs on /sys type sysfs (rw)                                                 
devpts on /dev/pts type devpts (rw,gid=5,mode=620)                             
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)                         
/dev/sde1 on /var/lib/mysql type ext3 (rw)                                     
[root@AMRStag ~]# cat /etc/fstab                                               
/dev/VolGroup00/LogVol00 /                      ext3    defaults        1 1   
LABEL=/boot            /boot                  ext3    defaults        1 2   
tmpfs                  /dev/shm                tmpfs  defaults        0 0   
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0   
sysfs                  /sys                    sysfs  defaults        0 0   
proc                    /proc                  proc    defaults        0 0   
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0   
#The following entry has been added by NetApp (SDU)                           
UUID=d6aba528-b7c1-4cf3-a0ea-b1bb0ddde1f6      /usr/local      ext3           
#The following entry has been added by NetApp (SDU)                           
UUID=13bc983c-8198-4586-ada4-be065bcaa7a1      /var/lib/mysql  ext3           
[root@AMRStag ~]#


DrLove73 08-17-2010 03:35 PM

Last row of fstab might need extra options, bout mount says its ReadWrite, so I do not think is fstab option (someone should confirm this).

Mount says /dev/sde1 is mounted to /var/lib/mysql. Is that NetApp LUN? Fstab reads that both "/usr/local" and "/var/lib/mysql" are on separate partitions, but mount does not see any "/usr/local". That should not be happening, right?

Do you have ANY files or folders on that NetApp partition? Could it be it's broken/not formated or similar? Can you check NetApp settings? For now try dissabling both NetApp partitions and allow both "/usr/local" and "/var/lib/mysql" to be on root partition, like before you started. Then try mounting those LUN's on separate, irelevant, mount points, just to test them before use. Then when you are pleased with results change mount points.

quanta 08-17-2010 09:29 PM

I haven't had any experience with NetApp LUN but it seems you have a problem with your device: http://serverfault.com/questions/124...only-from-a-di

yjd 08-18-2010 08:09 AM

I have setup other Red Hat like this with that problem. The only thing different is the developer went and changed the mount to different folders and setup MySQL.

I'm going to have them try one of my other Red Hat (I have one setup exactly the same) and we'll see if that works better or not.

yjd 08-18-2010 08:31 AM

I restarted the server just to see how it worked redid those commands and here is my result

Code:

<<< Log from 192.168.21.222 started August 18, 2010, 07:30:18 >>>
[root@amr55t ~]# ls -l /var/lib/mysql                                         
total 20568                                                                   
-rw-rw---- 1 mysql mysql 10485760 Aug 16 10:26 ibdata1                         
-rw-rw---- 1 mysql mysql  5242880 Aug 16 10:26 ib_logfile0                     
-rw-rw---- 1 mysql mysql  5242880 Aug 16 10:11 ib_logfile1                     
drwx------ 2 mysql mysql    4096 Aug 16 10:11 mysql                           
-rw-r----- 1 mysql mysql    2741 Aug 16 10:26 mysqld.log                     
-rw-rw---- 1 mysql mysql        6 Aug 16 10:26 mysqld.pid                     
srwxrwxrwx 1 mysql mysql        0 Aug 16 10:26 mysql.sock                     
drwx------ 2 mysql mysql    4096 Aug 16 10:11 test                           
[root@amr55t ~]# mount                                                         
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)                           
proc on /proc type proc (rw)                                                   
sysfs on /sys type sysfs (rw)                                                 
devpts on /dev/pts type devpts (rw,gid=5,mode=620)                             
/dev/sda1 on /boot type ext3 (rw)                                             
tmpfs on /dev/shm type tmpfs (rw)                                             
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)                         
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)                         
/dev/sdc1 on /usr/local type ext3 (rw)                                         
/dev/sde1 on /var/lib/mysql type ext3 (rw)                                     
[root@amr55t ~]# cat /etc/fstab                                               
/dev/VolGroup00/LogVol00 /                      ext3    defaults        1 1   
LABEL=/boot            /boot                  ext3    defaults        1 2   
tmpfs                  /dev/shm                tmpfs  defaults        0 0   
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0   
sysfs                  /sys                    sysfs  defaults        0 0   
proc                    /proc                  proc    defaults        0 0   
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0   
#The following entry has been added by NetApp (SDU)                           
UUID=d6aba528-b7c1-4cf3-a0ea-b1bb0ddde1f6      /usr/local      ext3           
#The following entry has been added by NetApp (SDU)                           
UUID=13bc983c-8198-4586-ada4-be065bcaa7a1      /var/lib/mysql  ext3

Looks like it's all good now... I'll talk with my developer to see what they did to the system.


All times are GMT -5. The time now is 08:22 AM.