您的位置:首页 > 运维架构 > Linux

Linux之下MySQL安装的三种方案的比较

2016-03-25 14:04 477 查看
如何在Linux操作系统下对MySQL进行正确的安装,以及有对不同MySQL安装的方案的比较。

其中包括使用rpm对其进行安装,二进制安装,源码安装这三种方案的比较。

  安装方法比较

  一.使用rpm安装

  安装简单,适合初学者学习使用

  1. 需要单独下载客户端和服务器

  2. 安装路径不灵活,默认路径不能修改,一台服务器只能MySQL安装一个 MySQL。

--------------------------------下面是oracle官方文档的部分指导说明:---------------------------------

  文件布局

  MySQL Installation Layout for Linux RPM Packages from the MySQLDeveloper Zone

DirectoryContents of Directory
/usr/bin
Client programs and scripts
/usr/sbin
The
mysqld server
/var/lib/mysql
Log files, databases
/usr/share/info
MySQL manual in Info format
/usr/share/man
Unix manual pages
/usr/include/mysql
Include (header) files
/usr/lib/mysql
Libraries
/usr/share/mysql
Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for databaseinstallation
/usr/share/sql-bench
Benchmarks
 MySQL Linux RPM Package Platforms

PLATFORM
Value
Intended Use
linux_glibc25
Platform independent, should run on any Linux distribution that supports
glibc
2.5
rhel5
Red Hat Enterprise Linux 5
el6
,
el7
Enterprise Linux 6 or 7
sles11
,
sles12
SUSE Linux Enterprise Server 11 or 12
In MySQL 5.6, only
linux_glibc2.5
packages are available currently.

The
CPU
value indicates the processor type or family for which the package is built, as shown in the following table.

Table 2.8 MySQL Linux RPM Package CPU Identifiers

CPU
Value
Intended Processor Type or Family
i386
,
i686
Pentium processor or better, 32 bit
x86_64
64-bit x86 processor
To see all files in an RPM package (for example, a
MySQL-server
RPM), run a command like this (modify the platform and CPU identifiers appropriately for your system):

shell> [code]rpm -qpl MySQL-server-
VERSION
.linux_glibc2.5.i386.rpm

[/code]
To perform a standard minimal installation, install the server and client RPMs:

shell> [code]rpm -i MySQL-server-
VERSION
.linux_glibc2.5.i386.rpm

shell>
rpm -i MySQL-client-
VERSION
.linux_glibc2.5.i386.rpm

[/code]
To install only the client programs, install just the client RPM:

shell> [code]rpm -i MySQL-client-
VERSION
.linux_glibc2.5.i386.rpm

[/code]
大多数情况下,下载MySQL-server 和MySQL-client 就够用了,安装方法如下:

  shell> rpm -ivh MySQL-server-VERSION.i386.rpm

  shell> rpm -ivh MySQL-client-VERSION.i386.rpm

  二.二进制安装

  1. 安装简单

  2. 可以地安装到任何路径下,灵活性好

  3. 一台服务器可以MySQL安装多个 MySQL

  1) 已经经过编译,性能不如源码编译的好

  2) 不能灵活定制编译参数

  ----------------------------下面是oracle官方给出的安装指导:------------------------------

On Unix, to install a compressed tar file binary distribution, unpack it at the installation location you choose (typically
/usr/local/mysql
). This creates the directories shown in
the following table.

Table 2.3 MySQL Installation Layout for Generic Unix/Linux Binary Package

DirectoryContents of Directory
bin
,
scripts
mysqld server, client and utility programs
data
Log files, databases
docs
MySQL manual in Info format
man
Unix manual pages
include
Include (header) files
lib
Libraries
share
Miscellaneous support files, including error messages, sampleconfiguration files, SQL for database installation
sql-bench
Benchmarks
Debug versions of the
mysqld binary are available as
mysqld-debug. To compile your own debug version of MySQL from a source distribution, use the appropriate configuration options to enable debugging support. SeeSection 2.9,
“Installing MySQL from Source”.

To install and use a MySQL binary distribution, the command sequence looks like this:

shell> [code]groupadd mysql

shell>
useradd -r -g mysql -s /bin/false mysql

shell>
cd /usr/local

shell>
tar zxvf 
/path/to/mysql-VERSION-OS
.tar.gz

shell>
ln -s 
full-path-to-mysql-VERSION-OS
mysql

shell>
cd 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 &

# Next command is optional
shell>
cp support-files/mysql.server /etc/init.d/mysql.server

[/code]

  三.源码安装

  1. 在实际安装的操作系统进行可根据需要定制编译,最灵活

  2. 性能最好

  3. 一台服务器可以安装多个 MySQL

  1. 安装过程较复杂

  2. 编译时间长

  bin客户端程序和脚本

  include/MySQL包含(头)文件

  info Info格式的文档

  lib/MySQL库

  libexec MySQLd服务器

  share/MySQL错误消息文件

  sql-bench基准程序和crash-me测试

  var数据库和日志文件

  1)去掉不需要的模块

  源码MySQL安装由于可以灵活的进行数据库的定制编译,因此有更强的灵活性。某些编译选项可以大大增强我们数据库的性能。

  执行如下命令可以看到所有编译的配置选项:

  shell> ./configure --help

  如果只安装客户端,可以执行如下命令:

  shell> ./configure --without-server

  如果你不想要位于“/usr/local/var”目录下面的日志(log)文件和数据库,使用类似于下列configure 命令的一个:

  shell>./configure--prefix=/usr/local/MySQL shell>./configure--prefix=/usr/locallocalstatedir=/usr/local/MySQL/data

  第一个命令改变安装前缀以便将所有内容MySQL安装到“/usr/local/MySQL”下面而非默认的“/usr/local”。第二个命令保留默认安装前缀,但是覆盖了数据库目录默认目录(通常是“/usr/local/var”)并且把它改为/usr/local/MySQL/data。编译完MySQL后,可以通过选项文件更改这些选项修改socket 的默认位置:

  shell> ./configure\-- with-unix-socket-path=/usr/local/MySQL/tmp/MySQL.sock

  2)只选择要使用的字符集:

  改变安装后的默认字符集和排序规则:

  shell> ./configure -- with-charset=CHARSET ./configure --with-collation=COLLATION

  选择需要MySQL安装的字符集:

  shell>./configure --with-extra-charsets=LIST

  list可以是下面任何一项:

  空格间隔的一系列字符集名

  complex -,以包括不能动态装载的所有字符集all –,以将所有字符集包括进二进制

  3)使用pgcc编译:

  pgcc 2.90.29 或更新版:

  CFLAGS="-O3 -mpentiumpro -mstack-align-double" CXX=gcc \CXXFLAGS="-O3 -mpentiumpro -mstack-align-double \-felide-constructors -fno- exceptions -fno-rtti"

  4)使用静态编译以提高性能:

  shell>./configure --with-client-ldflags=-all-static\ --with-MySQLd-ldflags=-all-static

- ---------------------------------------oracle官方给出的指导说明--------------------------------

2.9.2 Installing MySQL Using a Standard Source Distribution

To install MySQL from a standard source distribution:

Verify that your system satisfies the tool requirements listed at
Section 2.9, “Installing MySQL from Source”.

Obtain a distribution file using the instructions in
Section 2.1.2, “How to Get MySQL”.

Configure, build, and install the distribution using the instructions in this section.

Perform postinstallation procedures using the instructions in
Section 2.10, “Postinstallation Setup and Testing”.

In MySQL 5.6, CMake is used as the build framework on all platforms. The instructions given here should enable you to produce a working installation. For additional information on usingCMake
to build MySQL, see
How to Build MySQL Server with CMake.

If you start from a source RPM, use the following command to make a binary RPM that you can install. If you do not haverpmbuild, use
rpm instead.

shell> [code]rpmbuild --rebuild --clean MySQL-
VERSION
.src.rpm

[/code]
The result is one or more binary RPM packages that you install as indicated inSection 2.5.5,
“Installing MySQL on Linux Using RPM Packages from Oracle”.

The sequence for installation from a compressed tar file or Zip archive source distribution is similar to the process for installing from a generic binary distribution (seeSection 2.2,
“Installing MySQL on Unix/Linux Using Generic Binaries”), except that it is used on all platforms and includes steps to configure and compile the distribution. For example, with a compressedtar file source
distribution on Unix, the basic installation command sequence looks like this:

# Preconfiguration setup
shell> [code]groupadd mysql

shell>
useradd -r -g mysql -s /bin/false mysql

# Beginning of source-build specific instructions
shell>
tar zxvf mysql-
VERSION
.tar.gz

shell>
cd mysql-
VERSION

shell> [code]cmake .

shell>
make

shell>
make install

# End of source-build specific instructions
# Postinstallation setup
shell>
cd /usr/local/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 &

# Next command is optional
shell>
cp support-files/mysql.server /etc/init.d/mysql.server

[/code]
mysql_install_db creates
a default option file named
my.cnf
in the base installation directory. This file is created from a template included in the distribution package named
my-default.cnf


源码安装详细图文教程参考: http://blog.csdn.net/j7a4v5a2w2e8b9e4e6/article/details/50979167
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: