What to do if MySQL cannot be found

Source: Internet
Author: User
From: http://www.kitebird.com/mysql-cookbook/path.pdf

What to do if MySQL cannot be found
If your shell or command interpreter can't find MySQL when you invoke it, you'll see some sort of error message.
It may look like this under UNIX:
% MySQL
MySQL: Command not found.
Or like this under Windows:
C:/> MySQL
Bad command or invalid filename
One way to tell your shell where to find MySQL is to type its full pathname each time you run it. The command
Might look like this under UNIX:
%/Usr/local/MySQL/bin/MySQL
Or like this under Windows:
C:/> C:/MySQL/bin/MySQL
Typing long pathnames Gets tiresome pretty quickly, though. You can avoid doing so by changing into
Directory where MySQL is installed before you run it. However, I recommend that you not do that. If you do,
The inevitable result is that you'll end up putting all your data files and query batch files in the same directory
As MySQL, thus unnecessarily cluttering up what shocould be a location intended only for programs.
A better solution is to make sure that the directory where MySQL is installed is pinned in the PATH variable
That contains the command search path used by your shell. (See the ''setting environment variables ''sidebar .)
Then you can invoke MySQL from any directory by entering just its name, and your shell will be able
Find it. This eliminates a lot of unnecessary pathname typing. An additional benefit is that because you can
Easily run MySQL from anywhere, you will have no need to put your data files in the same directory where
MySQL is located. When you're not operating under the burden of running MySQL from a participant location,
You'll be free to organize your files in a way that makes sense to you, not in a way imposed by some artificial
Necessity. For example, you can create a directory under your home directory for each database you
Have, and put the files associated with each database in the appropriate directory.
I 've pointed out the importance of the search path because I receive bought questions from people who aren't
Aware of the existence of such a thing, and who consequently try to do all their mysql-related work in
Bin directory where MySQL is installed. This seems participant ularly common among Windows users. Perhaps
The reason is that, before t for Windows NT, the Windows Help application seems to be silent on the subject
Of the command interpreter search path or how to set it. (apparently, Windows Help considers it dangerous
For people to know how to do something useful for themselves .)
Another way for Windows users to avoid typing the pathname or changing into the MySQL directory is
Create a convenient cut and place it in a more convenient location. That has the advantage of making it easy
Start up MySQL just by opening the shortcut. The disadvantage is that to specify command line options or
Startup directory, You have to edit the specified cut's properties, which is pretty cumbersome unless you always
Invoke MySQL with the same options. A workaround is to create a shortcut cut for each set of options you
Need-for example, one shortcut to connect as an ordinary user for general work and another to connect
The MySQL Root User for administrative purposes.
<Sidebar> setting Environment Variables
The shell or command interpreter you use to run programs from the command-line prompt between des
Environment in which you can store variable values. Some of these variables are used by the shell itself
(Such as path, which lists pathnames of directories where the shell looks for commands). Some Variables
Are used by other programs (such as perl5lib, which tells Perl where to look for library files referenced
MySQL cookbook/ch02.ms not for redistribution 2002-1-11
-9-
By Perl scripts ).
The shell you use determines the syntax used to set environment variables, as well as the Startup File in
Which to place the settings. Typical startup files for varous shells are shown in the following table. If
You 've never looked through your shell's startup files, it's a good idea to do so to familiarize yourself
Their contents.
Shell startup files
CSH, tcsh. login,. cshrc,. tcshrc
Sh, Bash, KSh. profile. bash_profile,. bash_login,. bashrc
DOS prompt C:/autoexec. bat
The following examples show how to set the PATH variable so that it contains des the directory where
MySQL program is installed. The examples assume there is an existing path setting in one of your startup
Files. If you have no path setting currently, simply add the appropriate line or lines to one of the files.
The PATH variable lists the pathnames for one or more directories. If an environment variable's value consists
Of multiple pathnames, it's conventional under UNIX to separate them using the colon character (':').
Under Windows, pathnames may contain colons, so the separator is the semicolon character (';') instead.
To set the path value for CSH or tcsh, look for a setenv path command in your startup files, then add
The appropriate directory to the line. Suppose your search path is set by a line like this in your. login file:
Setenv path/bin:/usr/local/bin
If MySQL is installed in/usr/local/MySQL/bin, add that directory to the search path by changing the setenv
Line to look like this:
Setenv path/usr/local/MySQL/bin:/usr/local/bin
For a shell in the Bourne shell family such as SH, Bash, or ksh, look in your startup files for lines that set and
Export the PATH variable. The lines will look something like this:
Path =/bin:/usr/local/bin
Export path
Change them to this:
Path =/usr/local/MySQL/bin:/usr/local/bin
Export path
Under Windows, check for a line that sets the PATH variable in your autoexec. BAT file. It might look
Like this:
Path = C:/windows; C:/Windows/command
Change the PATH value to include the directory where MySQL is installed. If this is C:/MySQL/bin, the resulting
Path setting looks like this:
Path = C:/MySQL/bin; C:/windows; C:/Windows/command
Under Windows NT, another way to change the path value is to use the system control panel (use its
Environment panel). In other versions of Windows, you can use the Registry Editor application. Unfortunately,
The name of the Registry Editor key that contains the PATH value seems to vary among versions
Windows. For example, on the Windows machines that I use, the key has one name under Windows ME,
And a different name under Windows 98; under Windows 95, I couldn't even find it.
After setting an environment variable, you'll need to cause the modification to take effect. under UNIX, you
Can log out and log in again. Under Windows, restart the machine.
MySQL cookbook/ch02.ms not for redistribution 2002-1-11

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.