installing MySQL on Unix

Source: Internet
Author: User
Tags header install php connect mysql mysql client mysql in parent directory php and
Mysql|unix can get several versions of the MySQL distribution. The current stable distribution has 3.22 version series. The version currently being developed is 3.23 series. Generally, you should use the highest numbered version in the series.
MySQL distribution can be in binary code, RPM and source code format. Binary code and RPM distribution are easy to install, but must accept the installation design and default configuration that is built into the distribution package. It is difficult to install the source code distribution because the software must be compiled, but the parameters can be more controlled. For example, you can compile only the points of the client program
Contract, instead of the server, you can change the location of the installation software and so on.
Distribution contract  Xing aluminum Lucky Huan 龌 furui Oh horseshoe torreya ?br> mysqld Server
Client programs (MySQL, mysqladmin, etc.) and client programming support environment (library and header files)
Document
Standard database
Language support Environment
The source program and binary code distribution contain all of the above. Each RPM file contains only some of the content, so you may need to install more than one R P M in order to get what you need.
If you plan to connect to a server running on another machine, you do not need to install the server, but you should install the client software:
If you do not run the server, only the client is required so that you can connect to the server on the other machine.
If you do run a server, you will want to be able to connect to this server from the host of the server instead of logging on to other machines that have client software, and then test your server.

MySQL Installation overview

Installing MySQL on UNIX involves the following steps:
1 Create a user's UNIX account and the group that the server will manipulate (if the server is being installed).
2 obtain and open the distribution package that you want to install. If you are using a source code distribution, compile and install it.
3 Run the mysql_install_db script to initialize the data directory and permission table (only allow first installation).
4) Start the server.
5) See the 11th chapter, familiar with the general management process. In particular, you should read the server settings and shutdown as well as the paragraphs that run the server as unprivileged users.

Create a MySQL user account

If you only need to run the MySQL client software instead of running the MySQL server, you can skip this section.
The MySQL server can be run as any UNIX user on the system, but for security and confidentiality reasons, it is best to not run the server as root. It is recommended that you create a separate account for MySQL management and run the server with that user. This allows you to log on as the user and have full permissions in the directory for maintenance and troubleshooting. Create
The process of user accounts varies depending on the system. For more information, refer to the appropriate literature.
This book will mysqla D m and mysqlg R p respectively for UNIX users and for this account's group name. If you intend to install MySQL only for your own use and you can run it yourself, Mysqladm and MYSQLG R p that appear anywhere in this book can be replaced with your own login and group names. If you install from the rpm file, the installation process with RPM will automatically create a user named MySQL. In this case, you can replace MySQL with Mysqla d M.
The benefits of using a stand-alone, unprivileged account instead of running MySQL's R o T are:
If you do not run MySQL with root, no one can exploit this server's security vulnerabilities to obtain root access.
It is more secure for unprivileged users to perform MySQL administration tasks than root.
The server will create mysqladm files that are not owned by Root. The less files you have on the system, the better the R o T.
Separating MySQL's activities from its own account can be conceptually clearer, and it's easier to see what's on the system related to MySQL. For example, in the directory where the core file is saved, there is a separate file for MySQL user mysqladm. Otherwise, the MySQL corn job will be located in the root file and will be executed periodically as root with other things.

Obtaining and installing a MySQL distribution contract

In the following instructions, we use the version to represent the version number of MySQL, using the platform to represent the platform name on which to install. They are also used in the distribution package file name to easily identify the distribution and separate the distribution packages. The version number is something like 3.22.26 or 3.23.4-alpha, and the platform name is something like sgi-irix6.3-mips or D e c-osf4-0b-alpha.
1. Install binary code distribution system
The binary code distribution file has a name such as the M s Q l-ver s i o n-p l a t f o r m r.gz. Obtain the ideal version and platform of the distribution file and put it in the specified installation MySQL directory, such as/US r/l o c a L.
Open the distribution package with any of the following commands (if the TAR version does not support the Z option for uncompressed distributions, you should use the second command):
% tar zxf mysql-version-platform.tar.gz
% Gunzip < mysql-version-platfrom.tar.gz | Tar XF
Open the distribution to create a directory that contains the contents of the distribution Mysql-ver s I o n-p l a t f o r M. To make it easier to reference this directory, you can create a symbolic connection:
% ln-s mysql-version-platorm MySQL Now, if you install MySQL in the/usr/local directory, you can refer to the installation directory for/US r/l o c a l/mysql.
If you are only prepared to use the client support environment provided by the distribution and do not run the server, the installation is complete. If you are installing MySQL for the first time, refer to a. 3. Section 4, "Initializing Data directories and permission tables." If you are updating an existing installation, refer to a. 3. Section 5, "Start the server."
2. Installation of RPM distribution contract
The RPM file is available for MySQL installation on Linux systems. They have the following file name:
Mysql-ver s i o n-p l a t f o r m.rpm Server software.
Mysql-c L i e n T. ver s i o n-p l a t f o r m.rpm client program.
mysql-d e v e L. ver s i o n-p l a t f o r m.rpm Writing client program development Support environment (client library and header file). If you want to use or write a Perl DBI script that accesses the MySQL database, you need it.
Mysql-b e n c h. ver s i o n-p l a t f o r m.rpm Standard and test. Perl and Msql-mysql-modules modules are required. A mysql-mysql-modules rpm file can be obtained on w W w.mysql.com.
Mysql-ver s i o n. src.rpm the source code for servers, clients, standards, and tests.
If you install from RPM, you do not need a specific directory, because the RPM file contains information that specifies where to install the included files. For any RPM file R P m _ F i l E, you can use the following commands to know where the content will be installed:
% RPM-QPL Rpm_file
To install an RPM file, use the following command:
% Rpm-i Rpm_file
The components of MySQL are divided into different rpm files, so you may need to install more than one R P M. To install the client support environment, you can use the following commands:
% Rpm-i mysql-client-version-platform.rpm
Install the server support environment, using the following commands:
% Rpm-i mysql-version-platform.rpm
If you plan to write your own program using the client programming support environment, you should install the RPM file for development:
% Rpm-i mysql-devel-version-platform.rpm
If you plan to use the client support environment provided by the distribution, and you are not ready to use the server, the MySQL installation is over. If you are installing MySQL for the first time, refer to a. 3. Section 4, "Initializing Data directories and permission tables." If you are updating an existing installation, refer to a. 3. Section 5, "Start the server."
If you want to install from the source code rpm file, use the following command:
% rpm--recompile mysql-version.src.rpm
3. Installation source code distribution
The source code distribution has the following example Mysql-ver s i o n. T a r.gz such a name, where version is the edition number of MySQL. Select the directory where you want the distribution to be placed under, and enter the directory. Obtain the distribution file and open it with one of the following commands (if the TAR version does not support the Z option for uncompressed distributions, you should use the second command):
% tar zxf mysql-version.tar.gz
% Gunzip < mysql-version.tar.gz | Tar XF
Open the distribution to create a directory containing the contents of the distribution mysql-ver s i o n, and enter this directory.
% CD Mysql-version
This distribution package needs to be configured and compiled prior to installation. If the steps fail, you should refer to the "Installing MySQL" chapter of the MySQL Reference Guide, paying special attention to the system descriptions that it contains for various machine-specific purposes.
To configure a distribution by using the Configure command:
%./configure
You can specify options for configure. To get the available options table, execute the following command:
%./configure--help
The following list gives some of the configuration options that many people find useful:
--without-server only establishes the configuration of the client Support environment (client program or client library). You should select this option if you intend to access a server that is running on another machine.
--prefix = p a t h _ name defaults, the installation root directory is/US r/l o c a L. Data directories, clients, servers, client libraries, and header files are installed in the root directory in V a r, b i n, l I b e x e C, LIB, and include directories. If you want to change the root directory of the installation, use the--prefix option.
--localstatedir = p a t h _ name this option to change the location of the data directory. Use this option if you do not want the database to be saved under/usr/local/var.
--with-low-memory sql/sql_yacc.cc Source code files require a large amount of compile memory, which can sometimes lead to installation failures. The performance of this issue includes information about "fatal signal 11" or a virtual memory exhaustion error message. --The W i t h-l o w-memory option invokes the compiler with the option to generate low memory consumption.
After the Configure has been executed, compile the distribution and install it:
% make
% make Install
If you do not use the--prefix option to specify a directory with write permissions, you need to execute the installation command as root.
If you are only prepared to use the client support environment provided by the distribution and do not run the server, the MySQL installation is complete. If you are installing MySQL for the first time, refer to a. 3. Section 4. If you are updating an existing installation, refer to a. 3. Section 5, "Start the server."

Initializing data directories and permission tables

Before you can take advantage of MySQL installation, you need to initialize a MySQL database that contains a list of permissions that control network access to the server. This step is only required for new installations and when you intend to run the server. Those who only perform installation of the client support environment can skip this section. For binary code distribution, from the installation directory (b i n created by the distribution contract)
Directory's parent directory) to execute commands. For the source-code distribution, execute the command from the high level directory of the distribution package.
Data D I R is the path name of the directory. In general, execute the following commands as root. If you are logged on as a mysqladm, or if you are installing it under your account because you intend to run MySQL yourself, you may not execute the command as R o T, and you can skip the chown and chmod commands.
Run the mysql_install_db script to set the default permission table (if you are installing with a RMP file, you do not need to do this because the mysql_install_db will run automatically):
# scripts/mysql_install_db
If mysql_install_db fails, refer to the "Install MySQL" chapter of the MySQL reference guide to see what the chapter says about the problems encountered and try again. Note that if the mysql_install_db does not complete successfully, any of the permission tables it establishes may be incomplete. They should be deleted because mysql_install_db does not attempt to rebuild a table that already exists. You can delete the entire MySQL database using the following statement.
# RM-RF Datadir/mysql after running mysql_install_db, if you are installing a previous version of MySQL3.22.10, you should turn off the server (mysql_install_db will do this automatically for newer versions):
# bin/mysqladmin--user=root shutdown
After the server shuts down, change the owner of the users and groups all the file modes under the Data directory:
# chown-r Mysqladm.mysqlgrp DataDir
# chmod-r go-rwx DataDir
The chown command changes the owner of the MySQL user, and the chmod change mode excludes all people except Mysqladm.

Start the server

This step is only required when you want to run the server. Those that only require a client's installation can skip this step. The commands in this section should be executed in the same directory as the one given in the previous section. The command is normally run as the root user. If you are logged in as a Mysqla d m user, or if you install MySQL under your account, you can run the command without the R o T status, and you should omit the--user option.
Start the server with the following command:
# Bin/safe_mysqld--user=mysqladm &
The--user option tells the server to run as a mysqladm. If you want to enable logging, use the following command:
# Bin/safe_mysqld--user=mysqladm--log &
The default installation allows Mysqlroot users to connect without a password. It's a good idea to set a password. You should also schedule the server to start and shut down when the system starts and shuts down. In addition, the update log is recommended because it is useful for the data recovery process. For a description of the completion of these activities, see Chapter 11th.

Installing the Perl DBI Support environment

If you want to write a Perl script that accesses the MySQL database, you should install the DBI software. DBI requires that the MySQL client programming support environment is already installed because it uses the MYSQLC client library. If you want to write web-based dbi scripts, you can also install the CGL.PM module. DBI software requires a fairly new version of Perl (5.004 or update). If Perl is not installed, visit http://www. Per L. C o m/, download the Perl distribution and install it before installing the DBI support environment.
The DBI support environment requires three modules that can be installed from source code or RPM files:
D a T a-d um per to easily handle the Perl data structure of the module.
DBI main DBI Drive.
Msql-mysql-modules connected to the MySQL server, DBI uses MySQL-specific driver.
If you are installing from the source code, you should install the module in the order given in the previous list. Otherwise, the test steps in the following installation instructions will be abnormal.
The installation of all three modules is similar. When installing from source, use one of the following commands to open the distribution package (the second command should be used if the TAR version does not support the Z option for uncompressed distributions):
% tar zxf dist_file.tar.gz
% Gunzip < dist_file.tar.gz | Tar XF
Then go to the distribution directory created by the TAR command and run the following commands (you may need to run these installation steps as root):
% Perl makefile.pl
% make
% make Test
% make Install
If you run the command for the previous msql-mysql-modules distribution, the Perl command raises the following questions when generating makefile:
· Which drivers do youwant to install? There are various combinations of MySQL and msql choices. Unless you are still running M SQL, choose MySQL to make it simpler.
· Does youwant to install the Mysqlperl emulation? Mysqlperl is MySQL's old Perl interface that has been invalidated. Unless there is an old Mysqlperl script and you want to enable the emulation support environment in the DBI module, the answer is N O.
· Where is your mysqlinstalled? This should be the grandparent directory that contains the MySQL header file, presumably/usr/local or/US r/l o C l/mysql, unless the MySQL is installed in a non-standard location.
· Which database should I use for testing the mysqldrivers? The default is T e S, unless anonymous access to it is turned off, this should be OK. When you turn off anonymous access, you need to give a database name that you have access to, and then specify a valid MySQL username and password for the problem that follows.
· On which host is the database running? If you are running a local server, localhost is OK. If not, specify a server host for which you have access. When the make Test command is executed, the MySQL server must be running on this host, or the test will fail.
· User name for connecting to the database?
Password for connecting to the database?
The user name and password used to test the connection to the MySQL server. The default setting, both questions can be answered by UN d e F. This will enable the driver to connect as an anonymous user. If you need a non-anonymous connection, you can specify a non-null value.
If you have problems installing the Perl module, refer to the Readme file for the appropriate distribution package and the mail archive for the DBI mailing list, because most of the answers to the installation questions are available from that point.
If you want to use C G I. P M, it may have been given in the Perl installation. Trial Run command Perldoc CGI. If a CGI document is displayed, the CGI is already installed. Otherwise, obtain the appropriate distribution and open and install the same instructions as the other Perl modules.
If you want to install the Mod_perl Apache module in order to use web-based DBI scripts, you can access the Mod_perl area of the Apache Web site in the following locations for more information:
http://perl.apache.org/

Installing PHP and Apache

Follow the instructions below to start the action. If you encounter a problem, see the "VERBOSE Insta L" section in the PHP distribution for i N S TA l files (reading the file is not a bad idea, it contains a lot of useful information).
These instructions assume that you have an Apache source code distribution available and will run PHP as an Apache module. It is also assumed that you have Apache 1.3.9 and PHP 3.0.12, and are located in a directory where you can locate the apache_1.3.9 and php-3.0.12 directories that contain the source code distribution package. If you have a different version or location, you should replace it with your actual version number and path name when you use the following instructions.
To configure and build PHP, you can start with the following commands (this process may seem strange, since you want to start with the Apache distribution, but it is right):
% CD apache_1.3.9
%./configure
Apache's configure command is required because some of the header files required by PHP are generated at configuration time. If you do not run configure in the Apache distribution, the PHP configuration process will not be able to locate the file. After configuring Apache, enter the PHP distribution directory, configure PHP, set it up, and install it. You can also install a copy of the PHP initialization file:

PHP's Configure command tells PHP that you want the MySQL support environment and points out where the Apache source code is located. The--enable-track-vars option converts the automatic conversion of the window input into a variable that can be easily accessed from within the PHP page. Make command to compile and install PHP. It is possible to initialize file P H p 3 as root installation. i n i.
When you build PHP as a module, copy the corresponding module directly to the Apache source tree to install it so that it can be connected to the Apache binary code. When you are finished, you can compile and install Apache as follows:
% CD. /apache_1.3.9
%./configure--activate-module=src/modules/php3/libphp3.a
% make
% make Install
These steps configure Apache to know the PHP module file and then build and install it. You should edit the Apache configuration file h T P D. c o n F so that Apache can identify the PHP script. PHP identification is based on the file name extension of the PHP script. For example, if you want Apache to recognize. php and. P H P 3, put the following two lines in the configuration file:
AddType application/x-httpd-php3.php
AddType application/x-httpd-php3.php3
The suffix used depends on how you intend to name the PHP script. PHP and. PhP3 may be the most commonly used. Another commonly used suffix is. P h t M L. If you want, you can enable them all. If you plan to install pages from other people who use these extensions, it's best to enable them.
You can also tell Apache to use index.php or INDEX.PHP3 as the default file for a directory when no file name is specified at the end of the URL. You may find the following lines in the configuration file:
DirectoryIndex index.html
Change it as follows:
DirectoryIndex index.html index.php index.php3
After you edit the Apache configuration file, end the httpd server (if one is running), and then start the new H T P D that you just installed. In many systems, the following command (performed as Root) completes this work:
#/usr/local/apache/bin/apachectl Stop
#/usr/local/apache/bin/apachectl Start
You should also set up Apache to start and close when the system starts and shuts down. Please refer to the Apache documentation for the appropriate instructions. Typically, it includes running Apachectl start when you import, and running Apachectl stop when you close.

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.