LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Can't change to run as user 'mysql' (https://www.linuxquestions.org/questions/linux-software-2/cant-change-to-run-as-user-mysql-441366/)

lostjohnny 05-03-2006 05:09 PM

Can't change to run as user 'mysql'
 
Dear all,

I've just upgraded to MySQL 4.0.16-0 from 3.23 using RPM. Now, the mysql server shuts down as soon as it starts up. The following appears in /var/log/mysqld.log

060503 21:46:42 mysqld started
Fatal error: Can't change to run as user 'mysql' ; Please check that the user exists!
060503 21:46:42 Aborting

060503 21:46:42 /usr/sbin/mysqld: Shutdown Complete

060503 21:46:42 mysqld ended

This happens at start-up and also if I manually invoke the start-up script as root.

However, if I make myself the user mysql and invoke the start-up script, i.e.

# su mysql
bash-2.05b$ /etc/init.d/mysql start
bash-2.05b$ Starting mysqld daemon with databases from /var/lib/mysql

..it works.

Obviously I need mysqld to start automatically at boot-time.

Any ideas, anyone, please?

TIA

Lost Johnny

jschiwal 05-03-2006 06:02 PM

The "mysql" user is supposed to be a system user. You probably should delete the mysql regular user before proceeding.
Then create a mysql group. You will need to do that first to create a new mysql system user who's primary group is "mysql".

You need to add a system user by the name "mysql" with the default group of "mysql" and the default shell of /bin/bash. Do not include a password, so that the account is locked.
The entry for the home page should be "/var/lib/mysql"
My entry for the mysql user looks like this:
mysql:x:60:103:MySQL database admin:/var/lib/mysql:/bin/bash
Your uid and gid will be different of course.
The first two columns of the mysql entry in /etc/shadow will look like this:
mysql:!:
The "!" character means that someone can't log into this account.

lostjohnny 05-04-2006 05:17 AM

Thanks jschiwal,

Same result, though.

I did the following...

# /usr/sbin/groupadd mysql
# /usr/sbin/useradd -r -g mysql -s /bin/bash -d /var/lib/mysql mysql
# /etc/init.d/mysql start
# Starting mysqld daemon with databases from /var/lib/mysql
060504 11:01:21 mysqld ended

Same entry in the log file as before.

Earlier, I did the same as above, but I made the group mysql a system group with the -r option to groupadd. Same result.

Lost Johnny

lostjohnny 05-04-2006 05:50 AM

OK,

Seeing as the rpm installation is supposed to create the user and group, I deleted the user (the group was deleted automatically when I did this) and ran the installs again. The user is created exactly as jschiwal says it should be (above) and the group is there as well. Both have system ids.

The installation automatically starts the server... and it shuts down again with the same error in the log.

Lost Johnny

lostjohnny 05-04-2006 11:41 AM

I can write a program that switches to user 'mysql' (below).
Could it be that mysqld complains that it can't when the problem is actually something else?

int main(void)
{
struct passwd *pwEntry;

pwEntry = getpwnam("mysql");
printf("User id of mysql is %d\n", pwEntry->pw_uid);

if (setuid(pwEntry->pw_uid)) {
perror("setuid ");
return 1;
}

printf ("Set uid to %d OK\n", pwEntry->pw_uid);
return 0;
}

Output:

# ./setuid
User id of mysql is 100
Set uid to 100 OK


Lost Johnny

lostjohnny 05-04-2006 04:13 PM

I've cludged round the problem.

I've created a new start-up script that calls the real one as the user mysql.

This is mymysql:

#!/bin/sh
#This is my cludge. If the normal mysql script is run as root, mysqld fails to switch user for some reason.
#This script executes the other script as mysql

case "$1" in
'start')

sudo -u mysql /etc/init.d/mysql start
;;
'stop')

sudo -u mysql /etc/init.d/mysql stop
;;
'restart')

sudo -u mysql /etc/init.d/mysql restart
;;
esac

I've changed the link /etc/rc5.d/S90mysql to link to /etc/init.d/mymysql.

I'd still like to know why mysqld was failing to switch user to mysql when started by root, though.

Lost Johnny

nathacof 07-04-2007 01:45 PM

I'm having the exact same problem on a Fedora VPS with cPanel.

If I su mysql I can start the MySQL server fine. Otherwise it fails:

Quote:

070703 14:36:46 mysqld started
Fatal error: Can't change to run as user 'mysql'. Please check that the user exists!
070703 14:36:46 Aborting

070703 14:36:46 /usr/sbin/mysqld: Shutdown Complete

070703 14:36:46 mysqld ended

lostjohnny 07-05-2007 03:08 AM

Nathacof,

My problems went away when I installed FC6.

I hope you find a proper solution, but in the meantime, have you tried my cludge start-up script I posted in reply #6?

Graham

nathacof 07-07-2007 08:17 PM

[update]
I contacted cPanel support, and they recognized it as a known bug with MySQL 4.0 which they now no longer support.

If you upgrade to a version greater than 4.0 you should be good to go!

:)

[/update]

taghi 11-21-2011 02:38 PM

I realize that I may be one of the few left supporting MySQL 4.0 deployments, but it may be of use to others who stumble onto this thread. We just moved our product from MySQL 4.0.16 on RedHat AS3 to 4.0.27 on AS5 and got bit by this "feature".

The MySQL AB built distributions are (were?) statically linked "to increase portability across distributions". Further, it seems that at some point around 4.0.20 they began building their binaries with the Intel compiler suite rather than GCC.

MySQL 4.0.16 worked fine for our product on both AS3 and AS5, but as soon as we moved to 4.0.27 on AS5 it would no longer start. We saw the "unable to change to mysql user"-type errors. Digging into the source code, getpwent() appeared to be failing.

My best guess is that something changed in NSS or PAM or something between AS3 and AS5. Since MySQL was statically linked against whatever was available in the distant past, it did not pick up the new "knowledge" it needed to interact correctly on newer systems.

As a "fix", I had to rebuild the 4.0.27 RPMs with the static linking disabled. This allowed it to pick up the correct behavior from libc, and viola! 4.0.27 now starts correctly -- without the su init script hack -- on AS5.


All times are GMT -5. The time now is 01:16 PM.