LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-03-2006, 05:09 PM   #1
lostjohnny
Member
 
Registered: May 2006
Distribution: Fedora Core 6
Posts: 37

Rep: Reputation: 15
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
 
Old 05-03-2006, 06:02 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.
 
Old 05-04-2006, 05:17 AM   #3
lostjohnny
Member
 
Registered: May 2006
Distribution: Fedora Core 6
Posts: 37

Original Poster
Rep: Reputation: 15
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
 
Old 05-04-2006, 05:50 AM   #4
lostjohnny
Member
 
Registered: May 2006
Distribution: Fedora Core 6
Posts: 37

Original Poster
Rep: Reputation: 15
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
 
Old 05-04-2006, 11:41 AM   #5
lostjohnny
Member
 
Registered: May 2006
Distribution: Fedora Core 6
Posts: 37

Original Poster
Rep: Reputation: 15
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
 
Old 05-04-2006, 04:13 PM   #6
lostjohnny
Member
 
Registered: May 2006
Distribution: Fedora Core 6
Posts: 37

Original Poster
Rep: Reputation: 15
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
 
Old 07-04-2007, 01:45 PM   #7
nathacof
Member
 
Registered: Aug 2004
Location: Bear, DE, USA
Distribution: Slackware 11, CentOS 5.2, Ubuntu
Posts: 124

Rep: Reputation: 17
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

Last edited by nathacof; 07-04-2007 at 01:48 PM.
 
Old 07-05-2007, 03:08 AM   #8
lostjohnny
Member
 
Registered: May 2006
Distribution: Fedora Core 6
Posts: 37

Original Poster
Rep: Reputation: 15
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
 
Old 07-07-2007, 08:17 PM   #9
nathacof
Member
 
Registered: Aug 2004
Location: Bear, DE, USA
Distribution: Slackware 11, CentOS 5.2, Ubuntu
Posts: 124

Rep: Reputation: 17
[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]
 
Old 11-21-2011, 02:38 PM   #10
taghi
LQ Newbie
 
Registered: Nov 2011
Location: Atlanta, GA
Distribution: Kubuntu 11.10
Posts: 1

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


Reply



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
Help! Cannot Add a User to User Manager or Change Root Password lennysokol Linux - General 2 06-25-2005 09:59 AM
what is the command to make a user change their password after creating a new user? naweenio Linux - Newbie 7 01-05-2005 07:07 AM
How do I change the cursors globaly for a user? and how do I change them in the E-WM? enigma Z Linux - Software 1 09-18-2004 03:59 PM
MYSQL on Slackware9.0 ./mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 13) Litn Linux - Software 2 09-02-2003 09:00 PM
libnss-mysql (Store your UNIX user accounts in MySQL) markus1982 Linux - Security 0 01-26-2003 02:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:06 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration