LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices

Reply
 
Search this Thread
Old 08-16-2010, 11:13 AM   #1
yjd
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Rep: Reputation: 0
Question 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
 
Old 08-16-2010, 11:48 AM   #2
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
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)

Last edited by quanta; 08-18-2010 at 11:52 PM.
 
Old 08-16-2010, 11:53 AM   #3
johnshen64
LQ Newbie
 
Registered: Jun 2010
Posts: 29

Rep: Reputation: 5
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.
 
Old 08-16-2010, 12:18 PM   #4
chickenjoy
Member
 
Registered: Apr 2007
Distribution: centos,rhel, solaris
Posts: 200

Rep: Reputation: 30
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.
 
Old 08-16-2010, 02:27 PM   #5
yjd
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 08-16-2010, 08:33 PM   #6
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
Run the commands below and give us the output:
Code:
# ls -l /var/lib/mysql
# mount
# cat /etc/fstab

Last edited by quanta; 08-18-2010 at 11:51 PM.
 
Old 08-17-2010, 01:49 AM   #7
DrLove73
Senior Member
 
Registered: Sep 2009
Location: Srbobran, Serbia
Distribution: CentOS 5.5 i386 & x86_64
Posts: 1,118
Blog Entries: 1

Rep: Reputation: 129Reputation: 129
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.

Last edited by DrLove73; 08-17-2010 at 01:52 AM.
 
Old 08-17-2010, 08:10 AM   #8
yjd
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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 ~]#
 
Old 08-17-2010, 03:35 PM   #9
DrLove73
Senior Member
 
Registered: Sep 2009
Location: Srbobran, Serbia
Distribution: CentOS 5.5 i386 & x86_64
Posts: 1,118
Blog Entries: 1

Rep: Reputation: 129Reputation: 129
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.

Last edited by DrLove73; 08-17-2010 at 03:37 PM.
 
Old 08-17-2010, 09:29 PM   #10
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
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
 
Old 08-18-2010, 08:09 AM   #11
yjd
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 08-18-2010, 08:31 AM   #12
yjd
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to start my cronjob manually? xpucto Linux - Newbie 5 08-10-2014 04:37 PM
Start FC10 in runlevel 3, and than MANUALLY start X - how? rylan76 Linux - Newbie 2 05-27-2009 07:22 AM
samba refuses to start on startup, but will start manually pepsimachine15 Linux - Software 8 04-20-2009 11:03 AM
I have RHEL 5.0 and MySQL start problem, my MySQL server doesn't start rsatya Linux - Enterprise 4 02-03-2009 12:04 PM
Mysql problem: after changing root password, cannot start onboot Swakoo Linux - General 3 09-18-2007 04:37 AM


All times are GMT -5. The time now is 01:41 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration