LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Starting mysql using login script (https://www.linuxquestions.org/questions/linux-newbie-8/starting-mysql-using-login-script-4175429476/)

zak100 09-28-2012 01:05 PM

Starting mysql using login script
 
Hi,
Can sombody plz guide me how to start mysql using a login script. I dont want to type pasword.

Zulfi.

fernfrancis 09-28-2012 02:57 PM

can you please elaborate

what operating system your using , the version of mysql etc ...

what do u mean by login script ? what are you trying to achieve?

zak100 09-29-2012 02:11 AM

Hi,
Thanks for your response. I am using Fedora 1o. I want to start sqld and some people on this forum helped me for this. However I have to use :
Code:

su
mysqld

commands which asks password. That's why I want to create a login script so that no body can see the passwd. Kindly guide me:

i)how to write the script for executing the above commands without providing the passwd. The script should be able to execute at the time of guest user's login.
ii) in which file i have to store the script.

Zulfi.

Wim Sturkenboom 09-29-2012 12:39 PM

Is there a specific reason why you don't want the mysql daemon to be started at startup?

Quote:

commands which asks password. That's why I want to create a login script so that no body can see the passwd.
Nobody can see the password when you type it ;)

Quote:

how to write the script for executing the above commands without providing the passwd
Not possible (to my knowledge) when using 'su'. I guess Fedora has support for 'sudo', so you should be able to set that up so (one or more) users can start the mysql daemon without need for a password.

A last note: your title states mysql (the mysql client), your thread is about mysqld (the mysql daemon). There is a difference between the two ;)

zak100 09-29-2012 01:11 PM

Thanks for the correction of the title.

Quote:

Is there a specific reason why you don't want the mysql daemon to be started at startup?

No. This is what i want. mysqld is not starting at boot time. I have to first login to guest account and then i have to run mysqld. Its a teaching environment. I want to start it after the OS (Fedora) is loaded or after the guest login. Otherwise i have to run mysqld on all PCs and this would allow leakage of passwd.

I want to start mysqld at startup or at guest login and this is what i am looking for.

I dont know about sudo but how can i use it in a login script?

Zulfi.

Wim Sturkenboom 10-01-2012 02:31 AM

Quote:

I want to start mysqld at startup or at guest login
If it does not matter, let it start when the system boots (you don't need to know the password for that). If that does not work, check why it does not work and fix that. I'm not a fedora man so I can't say what to do to get it automatically started in fedora.

Quote:

I dont know about sudo but how can i use it in a login script?
Code:

sudo mysqld
But you have to setup 'sudo', something I have not played with.

Maybe more knowledgeable people can give the finer details.

_dkode_ 10-01-2012 04:39 AM

see http://www.mjmwired.net/resources/mj...es.html#enable
It explain how to set up services in fedora.

There is some graphical utilities where you can enable or disable services by clicking the checkboxes.

or you can allow some users with permission to run specified commands as root by sudo, all you need is to edit /etc/sudoers file using visudo.
eg:-
[user] ALL=(ALL) NOPASSWD: [command]
replace [user] and [command] with appropriate values.
then you can execute:
sudo [command] without any password if logged in as [user].

Also check.
man sudo
man sudoers

zak100 10-01-2012 12:51 PM

Thanks _dkode_ and Wim Sturkenboom. I would try on your advice.

Zulfi.

zak100 10-02-2012 05:27 AM

Hi,
I tried to change the following line in sudoers file:

Code:

# %wheel ALL=(ALL) NOPASSWD:ALL
with
Code:


guest ALL=(ALL) NOPASSWD:sqld

but its giving me error when i tried to save the file. It says:
Code:

>>> sudoers file: syntax error, line 84 <<<
what now?

Kindly guide me.

Zulfi.

_dkode_ 10-02-2012 07:52 AM

use the full path(absolute path) for the command.
if you don't know the path, use 'whereis' to find it.

Assuming you need to run sqld as root.

#whereis sqld
this will give you the path, lets say /usr/sbin/sqld
then you can change your sudoers entry to:
Quote:

guest ALL=(ALL) NOPASSWD: /usr/sbin/sqld
you may need to use mysqld instead of sqld

zak100 10-03-2012 05:37 AM

Hi,

Thanks for your response.

I tried :
Code:

## Same thing without a password
guest ALL=(ALL) NOPASSWD: /usr/libexec/mysqld

but I am getting following error:
Code:

[guest@HP-UX646UU ~]$ sudo service mysqld start
[sudo] password for guest:
Sorry, user guest is not allowed to execute '/sbin/service mysqld start' as root on HP-UX646UU.
[guest@HP-UX646UU ~]$

The root path for mysqld is:

Code:


[guest@HP-UX646UU ~]$ su
Password:
[root@HP-UX646UU guest]# whereis mysqld
mysqld: /usr/libexec/mysqld /usr/share/man/man8/mysqld.8.gz

Kindly guide me with this problem.

Zulfi.

Shammyhealz 10-03-2012 07:51 AM

I'm a bit of a noob, so I may be wrong, but I didn't think gz was a type of executable file? Google seems to confirm this.

Also, it would appear that you may have changed your sudoers file to make the sudo command log in as guest, not as root.

Wim Sturkenboom 10-03-2012 11:42 AM

@Shammyhealz: Look at the location the the gz-file; it's just the man page for mysqld

_dkode_ 10-04-2012 03:52 AM

You are using: sudo service mysqld start
you need to add the command /sbin/service mysql start, in sudoers.
not mysqld

*edited

Quote:

Code:

## Same thing without a password
guest ALL=(ALL) NOPASSWD: /usr/libexec/mysqld

but I am getting following error:
Code:

Code:

[guest@HP-UX646UU ~]$ sudo service mysqld start
[sudo] password for guest:
Sorry, user guest is not allowed to execute '/sbin/service mysqld start' as root on HP-UX646UU.
[guest@HP-UX646UU ~]$


in this settup you can run, without password
Code:

sudo mysqld
to execute
Code:

sudo service mysqld start
without password, you need to add entry
Code:

guest ALL=(ALL) NOPASSWD: /sbin/service mysqld start
there is also a short cut to allow executing all command as root without password in sudo, I use that in my servers. but it is dangerous if the guest account is accessible to persons other than administrators. if you use it, use with care or do not use.
Code:

guest ALL=(ALL) NOPASSWD: ALL

catkin 10-04-2012 04:24 AM

Quote:

Originally Posted by Wim Sturkenboom (Post 4793723)
If it does not matter, let it start when the system boots (you don't need to know the password for that). If that does not work, check why it does not work and fix that.

+1 to that. It is the normal way to start mysqld and is routinely used on many many systems.

jschiwal 10-04-2012 06:07 AM

I agree. Mysqld is a daemon and should be running in the background.

What distro do you use? Use ckconfig to enable services for the proper run levels for RPM distros like Redhat. You may also have a GUI config program where yiu can do it as well.

Undo what you did for the guest user. Giving "guest" root rights without a password sound like a horror story sys admins tell be the campfire.

Also download the manual for mysql. It lists tasks you need to perform after installation, such as giving the mysql root user a password, and dropping the demo tables.

gopinathnatarajan 10-04-2012 10:05 AM

try it

#sudo mysqld

edit the file inside as

% guest ALL=(ALL) NOPASSWD: (ALL)

then restart the mysqld.

sudo /etc/init.d/mysqld restart

no need to stop and start the mysqld just restart it.

zak100 10-06-2012 12:01 PM

Hi,
Thanks for your guidance. I would check it on Monday.
Zulfi.

zak100 10-08-2012 01:43 AM

Hi,
I am still trying.

Zulfi.

zak100 10-08-2012 02:45 AM

Hi,
Thanks all of you who helped me with this problem. Its working. I tried on several computers but not on all. However, on RedHAt based computers i am getting some problem with service command. I have to check this again and let you people know if there is any problem. Otherwise I would declare this thread as solved.

Zulfi.

jschiwal 10-08-2012 10:22 PM

Code:

chkconfig --levels 35 mysql
or
Code:

chkconfig mysql 35
This will enable mysqld for run levels 3 and 5. Check the man page to see which will work. You may also need to use mysqld as the name instead. chkconfig is a wrapper around insserv so different distros may be slightly different. Newer distros may use systemd but still support starting services the old way.

Please stop trying to give "guest" users root access with sudo. The idea is inane and very dangerous.


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