As we mentioned before, MySQL is not a requirement to use PHP, however they often go hand in hand.
virtualinfocom will help you how to install MySQL
Oracle provides a set of binary distributions of MySQL. In addition
to binaries provided in platform-specific package formats, we offer
binary distributions for a number of platforms in the form of
compressed tar files
(
.tar.gz
files). For Windows distributions, seeSection 2.5, “Installing MySQL on Windows”.
If you want to compile a debug version of MySQL from a source
distribution, you should add
--with-debug
or--with-debug=full
to theconfigure command used to configure the
distribution and remove any
-fomit-frame-pointer
options.
MySQL tar file binary distributions have names of
the form
mysql-VERSION
-OS
.tar.gz
,where
VERSION
is anumber (for example,
5.1.49
), andOS
indicates the type of operating systemfor which the distribution is intended (for example,
pc-linux-i686
).In addition to these generic packages, we also offer binaries in
platform-specific package formats for selected platforms. See the
platform specific sections for more information, for more
information on how to install these.
You need the following tools to install a MySQL
tar file binary distribution:
GNUgunzip
to uncompress the distribution.
A reasonable tar to unpack the distribution.
GNU tar is known to work. Some operating
systems come with a preinstalled version of
tar that is known to have problems. For
example, the tar provided with early versions
of Mac OS X, SunOS 4.x, Solaris 8, Solaris 9, Solaris 10 and
OpenSolaris, and HP-UX are known to have problems with long file
names.
On Mac OS X, you can use the preinstalled
gnutar program.
On Solaris 10 and OpenSolaris you can use the preinstalled
gtar.
On other systems with a deficient tar,
you should install GNU tar first.
Warning
If you have previously installed a MySQL installation using youroperating system native package management system, such as
yum
or apt-get
, you mayexperience problems installing using a native binary. Make sure
your previous MySQL previous installation has been removed
entirely (using your package management system), and that any
additional files, such as old versions of your data files, have
also been removed. You should also check the existence of
configuration files such as
/etc/my.cnf
orthe
/etc/mysql
directory have been deleted.The basic commands that you must execute to install and use a MySQL
binary distribution are:
Note
The following process assumes that you have root (administrator)access to your system. Alternatively you can prefix each command
using the sudo (Linux) or
pfexec (OpenSolaris) command.
shell>groupadd mysql
shell>useradd -g mysql mysql
shell>cd /usr/local
shell>gunzip <
shell>/path/to/mysql-VERSION-OS
.tar.gz | tar xvf -ln -s
shell>full-path-to-mysql-VERSION-OS
mysqlcd mysql
shell>chown -R mysql .
shell>chgrp -R mysql .
shell>scripts/mysql_install_db --user=mysql
shell>chown -R root .
shell>chown -R mysql data
shell>bin/mysqld_safe --user=mysql &
a binary distribution follows:
Note
The following process assumes that you have root (administrator)
access to your system. Alternatively you can prefix each command
using the sudo (Linux) or
pfexec (OpenSolaris) command.
-
If your system does not already have a user and group for
mysqld to run as, you may need to create one.
shell>
groupadd mysql
shell>useradd -g mysql mysql
Note
The above will create a user that has login permissions to
your server. You may wish to disable the account, as the user
is only required for ownership, not login, purposes.
These commands add themysql
group and the
mysql
user. The syntax for
useradd and groupadd may
differ slightly on different versions of Unix, or they may have
different names such as adduser and
addgroup.
You might want to call the user and group something else instead
ofmysql
. If so, substitute the appropriate
name in the following steps.
-
Pick the directory under which you want to unpack the
distribution and change location into it. In the following
example, we unpack the distribution under
/usr/local
. (The instructions, therefore,
assume that you have permission to create files and directories
in/usr/local
. If that directory is
protected, you must perform the installation as
root
.)
shell>
cd /usr/local
Obtain a distribution file using the instructions in
Section 2.1.3, “How to Get MySQL”. For a given release, binary
distributions for all platforms are built from the same MySQL
source distribution.
-
Unpack the distribution, which creates the installation
directory. Then create a symbolic link to that directory:
shell>
The tar command creates a directory namedgunzip <
shell>/path/to/mysql-VERSION-OS
.tar.gz | tar xvf -ln -s
full-path-to-mysql-VERSION-OS
mysql
mysql-
.VERSION
-OS
Theln
command makes a symbolic link to that
directory. This lets you refer more easily to the installation
directory as/usr/local/mysql
.
With GNU tar, no separate invocation of
gunzip
is necessary. You can replace the
first line with the following alternative command to uncompress
and extract the distribution:
shell>
tar zxvf
/path/to/mysql-VERSION-OS
.tar.gz -
Change location into the installation directory:
shell>
You will find several files and subdirectories in thecd mysql
mysql
directory. The most important for
installation purposes are thebin
and
scripts
subdirectories:
Thebin
directory contains client
programs and the server. You should add the full path name
of this directory to yourPATH
environment variable so that your shell finds the MySQL
programs properly. See
Section 2.14, “Environment Variables”.
Thescripts
directory contains the
mysql_install_db script used to
initialize themysql
database containing
the grant tables that store the server access permissions.
-
Ensure that the distribution contents are accessible to
mysql
. If you unpacked the distribution as
mysql
, no further action is required. If you
unpacked the distribution asroot
, its
contents will be owned byroot
. Change its
ownership tomysql
by executing the following
commands asroot
in the installation
directory:
shell>
The first command changes the owner attribute of the files tochown -R mysql .
shell>chgrp -R mysql .
themysql
user. The second changes the group
attribute to themysql
group.
-
If you have not installed MySQL before, you must create the
MySQL data directory and initialize the grant tables:
shell>
If you run the command asscripts/mysql_install_db --user=mysql
root
, include the
--user
option as shown.
If you run the while logged in as that user, you can omit the
--user
option.
The command should create the data directory and its contents
withmysql
as the owner.
After creating or updating the grant tables, you need to restart
the server manually.
-
Most of the MySQL installation can be owned by
root
if you like. The exception is that the
data directory must be owned bymysql
. To
accomplish this, run the following commands as
root
in the installation directory:
shell>
chown -R root .
shell>chown -R mysql data
If the plugin directory is writable by the server, it may be
possible for a user to write executable code to a file in the
directory usingSELECT
. This can be prevented by making
... INTO DUMPFILE
plugin_dir
read only to the
server or by setting
--secure-file-priv
to a directory
whereSELECT
writes can be made
safely.
If you want MySQL to start automatically when you boot your
machine, you can copy
support-files/mysql.server
to the location
where your system has its startup files. More information can be
found in thesupport-files/mysql.server
script itself and in Section 2.13.1.2, “Starting and Stopping MySQL Automatically”.
You can set up new accounts using the
bin/mysql_setpermission script if you install
theDBI
andDBD::mysql
Perl modules. See Section 4.6.14, “mysql_setpermission — Interactively Set Permissions in Grant
Tables”. For
Perl module installation instructions, see Section 2.15, “Perl Installation Notes”.
-
If you would like to use mysqlaccess and have
the MySQL distribution in some nonstandard location, you must
change the location where mysqlaccess expects
to find the mysql client. Edit the
bin/mysqlaccess
script at approximately
line 18. Search for a line that looks like this:
$MYSQL = '/usr/local/bin/mysql'; # path to mysql executable
Change the path to reflect the location where
mysql actually is stored on your system. If
you do not do this, aBroken pipe
error will
occur when you run mysqlaccess.
After everything has been unpacked and installed, you should test
your distribution. To start the MySQL server, use the following
command:
shell> bin/mysqld_safe --user=mysql &
If you run the command as root
, you must use the--user
option as shown. Thevalue of the option is the name of the login account that you
created in the first step to use for running the server. If you run
the command while logged in as
mysql
, you canomit the
--user
option.If the command fails immediately and prints
mysqld
ended
, you can find some information in thehost_name
.err
filein the data directory.
User Comments
Otherwise do a 'chmod g+w data'
pw groupadd mysql
pw useradd mysql
pw groupmod mysql -M mysql
pw groupshow mysql
More info can be found on the FreeBSD website:
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/users-groups.html
cd /usr/ports/databases/mysqlxx-server (xx is server verison)
make install clean (this installs and clean up after you)
cp /usr/local/share/mysql/abc.cnf /etc/my.cnf (abc is your choice of configuration file. options include my-huge, my-large, my-medium, my-small)
cp /usr/local/share/mysql/mysql.server /etc/rc.d/mysql.server
now you may install the db using :
mysql_intsall_db --user=mysql
verify that the mysql db in /var/db/mysql have the right user and group ownership (owner/group should be mysql)
If note just change the owner/group setting for the folder and sub-folders and files /var/db/mysql
You can now start the deamon
mysql_safe &
don't forget to change mysql admin password and imo also restrict admin user access only to local machine.
NOTE : You can change the location of the db file by including the directory switch in your mysql_install_db command (--basedir=path). You can also choose a different user to run your mysql daemon.
For fresh FreeBSD command you will notice that you need to use the full path to the executables : /usr/local/bin/mysqld_safe
1) A minor typo... "mysql_install_db" not "mysql_intsall_db"
2) Per his instructions, I did have to chgrp my /var/db/mysql files (chgrp -R mysql /var/db/mysql)
3) I'm assuming there's something wrong with my setup, since plain old "mysql_safe &" doesn't work for me. Instead I have to use this "cd /var/db/mysql ; /usr/local/bin/mysqld_safe &"
4) For reasons unknown to me, mysql doesn't start automatically on reboot. So I placed an sh file in /etc/rc.d that simply contains the mysql_safe call. (FYI, I do have mysql.server file in place)
mysqld_safe is the correct command.
Note that you can also either create a script that simply repeat these processes or update your make file to take these actions automatically.
If you have to install for multiple machines, a script is the way to go
mkdir /var/run/mysqld
chown -R /var/run/mysqld mysqld
chgrp -R /var/run/mysqld mysqld
In Fedora core 8 to start mysql service manually we need to create mysqld folder in /var/run and set permission as shown below
# groupadd mysqld
# useradd –g mysqld mysqld
# mkdir /var/run/msqld
# chown –R /var/run/mysqld mysqld
# chmod 770 /var/run/mysqld
On my linux I achieved that by appending <base_dir>/lib/mysql to the LD_LIBRARY_PATH environment variable. I also had to export the variable with
$ export LD_LIBRARY_PATH
An alternative is to add the mysql library dir to the set of standard library paths using ldconfig.
Can anyone post an updated install procedure?
<i>090327 15:04:12 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.</i>
After I did, I was able to start the daemon and run the upgrade script to create the plugin and host tables.
I am on linux-mint 4.0, which is basically Ubuntu 7. I would like to reiterate that without the --no-defaults option the mysql_install_db will not run correctly.
It really works thank you)
shell> cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf
#comment this would copy the desired config you want to /etc as my.cnf
shell> cp /usr/local/mysql/support-files/mysql.server /etc/init.d/
#comment this would copy the daemon for mysqld to init.d to be initialize it.
to start the mysqld
shell>/etc/init.d/mysql.server start
Few tips: If you use 'useradd mysql' like in this example - you get an account with which you can log in to KDE and has a '/usr/home/mysql' directory. You would also see it in the login splash. You need to do 'useradd -r mysql' so no home directory and account are created. The same for groupadd. Use the '-r' flag so the group gets a group id lower than 500 to be considered a system group.
No matter what I did I could not run the scripts in the $MYSQL_HOME/scripts or $MYSQL_HOME/bin with any other user than root. No 'chmode' command seemed to help. You have to perform the installation with the root account (e.g. su) plus to use the '--user=root' flag in every installation script.
I used the '/usr/local' dir to place the installation but I have a data partition under '/data' where I wanted all my large files to reside. I used the '--datadir=/data' flag to tell mysql where the db files will reside.
I could not set mysql to start automatically using the instructions here. I did the '/etc/init.d' linking, like it says here - but when I tried to run '/etc/init.d/mysql.server start' I got a permission error.
This was a show-stopper for me so I tried a different approach. I used 'urpmi mysql' to install the mysql package. This got me up and running plus auto-starting mysql in under 2 minutes.
Then, I checked how the installer configured the '/etc/init.d' linking and found out the links are totally different than what it says here. The installer also places the main mysql installation under '/var/lib'.
Then, in the '/etc/my.cfg' file - I changed the 'datadir' property to my own path '/data'. When I ran the '/etc/init.d/mysqld start' command, mysql complained about the /data/mysql' directory not existing, but, it created it, nonetheless, and continued flawlessly. It never complained about anything since. I recommend the 'urpmi mysql' apparoach which saves a lot of time.
BTW: The akonadi server uses a pre-existing mysql database. I had akonadi removed and manually deleted the default db because the 'urpmi' utility complained about a clash with the existing mysql-core package version which seems to be lower than the current mysql package needs. After installing the current mysql package version (5.1.42), I reinstalled akonadi and configured it to use my new mysql db. For this I used the desktop configuration tool advanced options (KDE). I worked fine with KDE without akonadi for a few days anyway. I'm not sure what's the use of akonadi on a single user laptop like mine.