At 10:44 AM -0600 7/25/01, Michael Nezi wrote:
>Saw your post on mysql.com and wondering if you could help me.

Working with the Mac OS X Terminal

Mac OS X comes with a Terminal application that can be used for 
issuing instructions to the OS from a command line. You will find it 
necessary at times to perform some tasks using the Terminal 
application and so should become a bit familiar with its use. When 
you open the terminal application it starts a shell specific for your 
user account. Many of the commands and utilities needed for 
administrative purposes however require that you open a root shell, 
in other words, you need to log in as the root administrator.

When you install Mac OS X you set up an Administrator user name and 
password, this OS user account allows you to perform administrative 
functions but is not the root account that has complete control over 
all functions of the system. Apple has elected to not enable this 
account by default. It must be explicitly enabled for it to be 
available. In my opinion, when administering MySQL on the command 
line using the terminal program on Mac OS X you are best off not 
enabling the root account. The reason for this is to lessen the 
chance that you will create files and install programs that can only 
be used by root, thus not allowing the system to work for a user 
account with fewer privileges. It is also common practice in UNIX not 
to use the root account to perform general tasks and it should only 
be used when it is necessary.

To work with just the Admin user name, prefix any command with 
"sudo". If a password is required, you will be prompted for it. The 
sudo program takes as an argument a command line to be executed as 
root. Your user account must be included in a configuration file to 
be allowed to utilize this command. This file also specifies the 
commands you can run, in the case of Mac OS X the user that you set 
up when installing the OS is included on this list by default and 
assigned privileges that allow it to perform any task that root is 
able to. For example, to run the above command use:

root% sudo ./mysqladmin -u root password thenewpassword

Alternatively, if you will be executing a series of commands as root 
then start with the "sudo su" or "sudo -s" command to start a new 
shell as the root user. Use exit to stop issuing commands as root and 
exit the shell. For example:

% sudo su
Password:
root% ./mysqladmin -u root password thenewpassword
root% (another command)
root% (another command)
root% exit

While sudo would require you to enter a password each time:

% sudo ./mysqladmin -u root password thenewpassword
password:
% sudo (another command)
password:
% sudo (another command)
password:
% sudo etc
password:

If you open a root shell to accomplish a series of tasks, there will 
not be a need to use "sudo" for each command.

Note that in this document, lines that begin with % indicate a UNIX 
command prompt, it may actually look more like:

[localhost:~] mcollins%

The text that follows is what would be typed into the terminal. In 
addition, root% at the start of the line indicates that the command 
needs to be issued while logged in as root or with root permissions.

The Root Account

If there are any other users with accounts on your server, it is 
essential that you protect the root account by creating a password 
for this account. Even if you are the only one with access to the 
machine, it is prudent to plug any holes that may be exploited by 
hackers. The key thing to keep in mind is that the OS root is not the 
same as the MySQL root. You don't need to have root access to the 
server to attempt to use the MySQL root account. There might be other 
user accounts to the server that may be able to navigate to the mysql 
utility and log in as the MySQL root with no password. This can 
happen even through a remote telnet session, since even though root 
is set to localhost only, a telnet session allows one to connect and 
work as a user would on the localhost.  Having no root password would 
mean this intruder could send any SQL command to the databases, and 
even delete them. The root account created in MySQL uses the name 
"root" by convention, it is not required that the account use the 
name "root", it could be changed to any name you want.

Setting the MySQL root password is an example of when you will need 
to use the Mac OS Terminal. The task of setting the root password is 
accomplished using mysqladmin, one of the utility programs installed 
by MySQL (and MySQL). The command is as follows:

root% cd /usr/local/
root% ./bin/mysqladmin --socket=/tmp/MySQL.sock -u root password thenewpassword

Tip: If a password was already set for MySQL root and you want to 
change the password, you could add the -p option (after root in the 
above command), you will then be prompted for the existing MySQL root 
password.

Starting and Stopping MySQL

Mac OS X has a problem with stopping MySQL, so you need to find the 
process ID and then kill safe_mysql first and then the mysqld second. 
To get the process ID:

% ps aux

(note the PID for safe_mysql and mysqld, in this example it is 290 and 302)

% sudo -s

root% kill 290
root% kill 302

If you need to restart MySQL for some reason, you can execute the two 
commands shown above, or execute the startup script as follows:

root% cd /Library/StartupItems/

root% ./MySQL

Or:

root% cd /usr/local/

root% ./safe_mysql &

The & instructs that the process run in the background.

TIP: In the simplest of terms, Unix commands are files that contain a 
script and have the execute bit turned on. To use a command that is 
not in the standard location for commands, precede the command with 
the shorthand "./" to mean "look in this folder for the command". To 
view the paths to your commands, use the following:

% echo $PATH

These paths are what the Unix OS uses to search for any command that 
is specified on the command line. If not command is found on any of 
the indicated paths an error occurs. The common location for locating 
scripts so that they behave like commands is in the directory:

/usr/local/bin

If you have an executable file in this location you are not required 
to indicate the path to the file to execute the contents of the file 
as a script.

-- 
Michael
__
||| Michael Collins       |||
||| Kuwago Web Services   |||      mailto:[EMAIL PROTECTED]
||| Seattle, WA, USA      |||      http://www.lassodev.com

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to