Installing MySQL Server

本文主要记载了通过编译方式进行软件/开发环境的安装过程,其他安装方式忽略!

文章背景:
因为php和Apache等采用编译安装方式进行安装,然而编译安装方式,需要c,c++编译环境,
通过apt方式安装build-essential $ sudo apt-get install build-essential
编译安装的步骤一般分为: 编译配置 $ ./configure --XXX(参数s)

编译配置的问题:
a、在没有安装之前,对软件无法全面了解 b、如果不全全面了解,又不知道该怎么安装(附带哪些参数)
c、可以先选择一个最简单的安装方式,随着使用,多次安装来解决这个问题 该过程比较复杂,需要很复杂的具体参数配置,具体参数通过 configure --help 查看 编译 $ make 安装 $ sudo make install


**************************************

Apache 安装

1、下载 httpd-2.2.11.tar.gz 2、解压
tar zxvf httpd-2.2.11.tar.gz 在执行tar指令的路径下,会产生一个httpd-2.2.11目录


3、查看一下编译的配置信息     

切换到解压之后的httpd-2.2.11目录    ./configure --help      通过本步骤可以了解有那些可以安装的模块,以及安装配置信息需要设置      进一步查看手册,也可以了解相关信息 
4、进行编译配置
$ ./configure --prefix=/usr/local/apache2   指定安装目录 --enable-so                                 允许使用外部so模块
--with-mpm=prefork                           url请求跳转策略
5、编译: $ make
6、安装:(使用sudo是因为要安装的路径/usr/local/apache2不属于个人路径) $ sudo make install 《安装完毕》

7、测试 修改httpd.conf。 将  #ServerName www.example.com:80 修改为 ServerName 127.0.0.1:80(localhost:80) 启动 sudo ./apachectl -k start 停止 sudo ./apachectl -k stop 重新起动 sudo ./apachectl -k restart (该命令有时无效,用stop+start代替)

****************************************

PHP安装

1、下载php-5.2.8.tar.gz 2、解压tar zxvf php-5.2.8.tar.gz
3、查看一下编译的配置信息
     切换到解压之后的httpd-2.2.11目录    ./configure --help      通过本步骤可以了解有那些可以安装的模块,以及安装配置信息需要设置      进一步查看手册,也可以了解相关信息
4、编译配置 ./configure --prefix=/home/guandl/webenv/php528 --enable-mbstring
--with-apxs2=/usr/local/apache2/bin/apxs 

5 编译 make
6、安装 sudo make install 《安装完毕》
7、复制php.ini
因为一般安装后的php目录$php/lib下没有php的配置文件,需要把解压目录下的php.ini-recommended复制到php的lib目录
sudo cp php.ini-recommended /home/guandl/webenv/php528/lib/php.ini
8、修改apache 的配置文件 httpd.conf 增加一下内容 LoadModule php5_module        modules/libphp5.so 安装php时候已经自动生成 AddType application/x-httpd-php .php 9、测试
编写一个php文件,如any.php <?php phpinfo(); ?>
放到apache的htdocs目录下 重新启动apache http://127.0.0.1/any.php

安装MySQL服务器

我们将学习如何 编译 安装 MySQL服务器 从源代码。 之后,我们将 配置 我们的服务器和基本功能 安全 它用于一般用途。 最后,我们将讨论 基础知识 MySQL服务器

安装 MySQL服务器 从源代码包括以下步骤。

1) - 1安装缺少的依赖项

2) 添加一个MySQL用户和组

3) 下载的源代码

4) 解包和安装

5) 后安装过程

6) - 2日安装缺少的依赖项

7) 安装检查

在安装 MySQL服务器 以下部分,建议查看。

确保MySQL服务器

定制MySQL服务器

MySQL服务器的基本知识

 http://howtolamp.com/lamp/mysql/5.6/installing/

1)安装缺少的依赖关系 Perl-GD 支持 MySQL服务器 需要安装Perl-GD包。 在这里安装说明

安装Perl GD

Perl GD 是一个autoloadable接口模块 GD 。 这是一个流行的库来创建和操纵 PNG 文件。 它是运行所需 Perl 脚本 graph-compare-results MySQL基准套件 CentOS v6.3 DVD1安装不来的 Perl GD 包中。 执行以下步骤来安装 Perl GD 注意: 基于规则的执行安装 iRULE4
如果你有一个互联网连接

如果你没有一个互联网连接
如果你有一个互联网连接 在终端,执行以下命令。

# yum install perl-GD
OPTIONS EXPLAINED
install
Is used to install the latest version of a package or group of packages while ensuring that all dependencies are satisfied. (See Specifying package names for more information) If no package matches the given package name(s), they are assumed to be a shell glob and any matches are then installed. If the name starts with an @ character the rest of the name is used as though passed to the groupinstall command. If the name starts with a - character, then a search is done within the transaction and any matches are removed. If the name is a file, then install works like localinstall. If the name doesn’t match a package, then package "provides" are searched (Eg. "_sqlitecache.so()(64bit)") as are filelists (Eg. "/usr/bin/yum"). Also note that for filelists, wildcards will match multiple packages.
[root@localhost ~]# yum install perl-GD
Loaded plugins: fastestmirror, langpacks
base                                                     | 3.6 kB     00:00     
extras                                                   | 3.4 kB     00:00     
updates                                                  | 3.4 kB     00:00     
(1/4): extras/7/x86_64/primary_db                          |  54 kB   00:00     
(2/4): base/7/x86_64/group_gz                              | 154 kB   00:00     
(3/4): updates/7/x86_64/primary_db                         | 1.7 MB   00:01     
(4/4): base/7/x86_64/primary_db                            | 5.1 MB   00:03     
Loading mirror speeds from cached hostfile
 * base: mirrors.skyshe.cn
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.pubyun.com
Resolving Dependencies
--> Running transaction check
---> Package perl-GD.x86_64 0:2.49-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package           Arch             Version                Repository      Size
================================================================================
Installing:
 perl-GD           x86_64           2.49-3.el7             base           173 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 173 k
Installed size: 394 k
Is this ok [y/d/N]: y 
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/perl-GD-2.49-3.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for perl-GD-2.49-3.el7.x86_64.rpm is not installed
perl-GD-2.49-3.el7.x86_64.rpm                              | 173 kB   00:00     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-1.1503.el7.centos.2.8.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : perl-GD-2.49-3.el7.x86_64                                    1/1 
  Verifying  : perl-GD-2.49-3.el7.x86_64                                    1/1 

Installed:
  perl-GD.x86_64 0:2.49-3.el7                                                   

Complete!
[root@localhost ~]# 

如果你没有一个互联网连接 找到一个系统,有一个互联网连接。 下载 Perl GD 包的CentOS v6.3 http://vault.centos.org/6.3/os/i386/packages/perl - gd - 2.44 - 3. - el6.i686.rpm

下载RPM的大小为180 KB。 在终端,改变控股RPM文件的目录。 执行以下命令。

# rpm -ivh perl-GD-2.44-3.el6.i686.rpm
 OPTIONS EXPLAINED

-i
This installs a new package.

-v
Print verbose information - normally routine progress messages will be displayed.

-h
Print 50 hash marks as the package archive is unpacked.  Use with -v|--verbose for a nicer display.

2)添加一个MySQL用户和组 运行 MySQL服务器 作为根用户是不安全的,所以不是明智的。 这是更好的运行 MySQL服务器 在一个有限的系统帐户特权。 所以我们将为MySQL创建用户和组。 在终端,执行以下命令。

# useradd -r -U mysql -M -d /usr/local/mysql/data
[root@localhost ~]# useradd -r -U mysql -M -d /usr/local/mysql/data
[root@localhost ~]# 


注意: 的主目录 mysql 用户将数据目录 /usr/local/mysql/data/ 。 这是因为我们计划安装MySQL服务器的目录 /usr/local/mysql/ 。 您可以使用一个不同的安装目录或数据存储,如果你的愿望。

OPTIONS EXPLAINED

-U
Create a group with the same name as the user and add the user to this group, in case USERGROUPS_ENAB in your /etc/login.defs is set to no. (By default this is set to yes).

-r
Create as system account

-M
Do not create the user´s home directory, in case CREATE_HOME in your /etc/login.defs is set to yes. (By default this is set to no). This is used because we do not want the files and directories contained in the skeleton directory to be copied to home directory.

-d
The new user will be created using HOME_DIR as the value for the user´s login directory. The default is to append the LOGIN name to BASE_DIR and use that as the login directory name. The directory HOME_DIR does not have to exist but will not be created if it is missing.

这将创建一个用户和组,命名为 mysql 。 他们将被创建为系统账户和没有密码设置。主目录将被设置为 /usr/local/mysql/data/ 但它将不会创建。 The login shell will be /bin/bash

3)下载源代码

MySQL社区服务器下载源代码 MySQL社区服务器的免费下载的版本 MySQL服务器 。 它可以从MySQL开发区域。

让我们转到 http://dev.mysql.com/downloads/ 。 的页面,点击 下载 选项卡上,将带我们去下载页面清单不同MySQL项目。 下面 MySQL社区服务器 MySQL Community Server, 点击 下载 链接,这将带我们到下载页面。 我们将会看到一个列表 一般可用(GA)版本 。 选择平台, 源代码 。 滚动到,我们将看到底部 通用Linux(架构独立),压缩的TAR存档  Generic Linux (Architecture Independent), Compressed TAR Archive。 单击 下载 按钮时,它将带我们到一个页面,我们可以用一个Oracle Web登录/注册账户。 如果你想要,你可以。 但我选择点击 不,谢谢,就开始下载。 。 这将启动下载

下载的文件 mysql-5.6.19.tar.gz 31.4 MB 在大小。

https://edelivery.oracle.com/EPD/Search/handle_go

Download  MySQL Cluster 7.4.6 TAR for Generic Linux (glibc2.5) x86 (64bit) V75610-01 481M

下载谷歌c++源代码嘲笑框架 谷歌c++ Mocking框架(gmock)是一个图书馆使用c++编写和模拟类。 MySQL服务器 使用它的 谷歌c++测试框架(gt) 基于单元测试。 如果你现在不下载这个,在配置过程中会显示以下错误。

Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.

即使你启用的选项 ENABLE_DOWNLOADS = 1 (即,假设你有一个活跃的网络连接),配置脚本将给你以下错误。

CMake Error: Problem with tar_extract_all(): Invalid argument
CMake Error: Problem extracting tar: /usr/src/mysql-5.6.19/source_downloads/gmock-1.6.0.zip

发生这种情况是因为MySQL Bug 69854年 ,这将 固定在MySQL 5.7.4里程碑14 。 为当前时间,我们必须解决这个。

谷歌c++嘲笑框架可以在Google代码项目托管。 转到 http://code.google.com/p/googlemock/ 。 的页面,点击 下载 选项卡上,将我们的页面下载清单。 版本的谷歌c++ Mocking框架,试图下载的配置脚本 1.6.0 。 所以点击 gmock-1.6.0.zip ,它将带我们去下载页面。 点击 gmock-1.6.0.zip 。 这将启动下载。 下载的zip文件 gmock-1.6.0.zip 2.0 MB 在大小。

4)拆包和安装 解包 确保你有复制下载的文件 mysql-5.6.19.tar.gz gmock-1.6.0.zip 目录 /usr/src/ 。 在终端,改变 /usr/src/ 目录中。

# cd /usr/src


提取gzip压缩文件包含 MySQL服务器

# tar -zxvf mysql-5.6.19.tar.gz
OPTIONS EXPLAINED

-x
extract files from an archive

-v
verbosely list files processed

-z
filter the archive through gzip

-f
use archive file or device ARCHIVE


将gmock zip文件解压到指定的目录

# unzip gmock-1.6.0.zip -d mysql-5.6.19/source_downloads
OPTIONS EXPLAINED

-d
An optional directory to which to extract files. By default, all files and subdirectories are recreated in the current directory; the -d option allows extraction in an arbitrary directory (always assuming one has permission to write to the directory). This option need not  appear  at the end of the command line; it is also accepted before the zipfile specification (with the normal options), immediately after the zipfile specification, or between the file(s) and the -x option. The option and directory may be concatenated without any white space between them, but note that this may cause normal shell behavior to be suppressed. In particular, ‘‘-d ~’’ (tilde) is expanded by Unix C shells into the name of the user’s home directory, but ‘‘-d~’’ is treated as a literal subdirectory ‘‘~’’ of the current directory.

这将创建一个目录命名 source_downloads mysql-5.6.19 目录和提取特徵的zip文件。


安装
注意: 基于规则的执行安装 iRULE1 iRULE3 现在我们将有一个目录 mysql-5.6.19 提取的文件。 改变目录的终端。

# cd mysql-5.6.19


cmake执行。 注意: 默认的安装目录 /usr/local/mysql/ 。 如果你想要改变它,使用的选项 CMAKE_INSTALL_PREFIX 例子: # cmake。 -DCMAKE_INSTALL_PREFIX = your_custom_location 默认的数据目录 /usr/local/mysql/data/ 。 如果你想要改变它,使用的选项 MYSQL_DATADIR 例子: # cmake。 -DMYSQL_DATADIR = your_custom_location 我们安装的默认配置选项,使用下面的命令 命令: # cmake。 韩 •配置选项的完整列表,参见以下链接 http://dev.mysql.com/doc/mysql-sourcebuild-excerpt/5.6/en/source-configuration-options.html

# cmake .

cmake会检查我们的系统所需的依赖项,分配值与系统相关的变量和使用这些值来生成Makefile。


执行。

# make

会看看我们 Makefile 、编译我们的程序代码并创建可执行文件描述的顺序。


执行make install。

# make install
OPTIONS EXPLAINED

install
install will look for the target install in Makefile, and install MySQL Server to the specified location.

5)安装过程 添加MySQL服务器可执行文件系统路径 MySQL服务器 可执行文件位于 /usr/local/mysql/bin/ 和他们43号。 我们不会为每个添加符号链接 /usr/bin/ 。 相反,我们将添加 /usr/local/mysql/bin/ 到系统 路径 变量。 路径 是一个环境变量,它必须提供给所有用户,在登录和shell。 我们必须添加一个脚本 /etc/profile.d/ 目录中。 注意: 阅读的区别 环境变量 局部变量 阅读的区别 登录Shell 非登录Shell

创建一个文件 mysql.sh /etc/profile.d/ 目录下面的内容。 这是 Bash shell

if ! echo ${PATH} | /bin/grep -q /usr/local/mysql/bin ; then
PATH=/usr/local/mysql/bin:${PATH}
fi

创建一个文件 mysql.csh /etc/profile.d/ 目录下面的内容。 这是给 C shell Tenex C shell

if ( "${path}" !~ */usr/local/mysql/bin* ) then
set path = ( /usr/local/mysql/bin $path )
endif

从这一刻起,任何新的登录shell或shell催生了会 /usr/local/mysql/bin/ 路径 变量。 但目前的外壳,我们正在没有它。 因为它是在脚本放在全球概要目录。 所以我们必须源对我们工作shell脚本。 我使用 Bash shell 。 所以我在我目前的终端执行下面的命令。

# source /etc/profile.d/mysql.sh

将MySQL服务器库添加到共享库缓存 MySQL服务器 图书馆是位于 /usr/local/mysql/lib/ 。 但这些还没有共享。 其他应用程序在运行时发现这些库,动态链接器缓存在Linux中必须更新这些库的信息。

创建一个文件 mysql.conf 在目录中 /etc/ld.so.conf.d / 的条目 /usr/local/mysql/lib

# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf


ldconfig运行。

# ldconfig

ld.so.conf ldconfig扫描。 d文件夹并更新共享库缓存,以便在运行时动态链接器可以找到他们。

添加MySQL服务器MANPATH手册 MySQL服务器 手册是位于 /usr/local/mysql/man/ 。 我们已经添加了 /usr/local/mysql/bin/ 到系统 路径 变量。 所以男人工具会自动搜索的位置 /usr/local/mysql/man/ 手册。 不需要额外的变化。

创建MySQL服务器授权表 在终端,改变 MySQL服务器 安装目录

# cd /usr/local/mysql


改变的所有者和组 /usr/local/mysql/ 目录的内容 mysql 。 这样做是为了安装 MySQL服务器 系统授权表。 我们将恢复权限。

# chown -R mysql:mysql .
OPTIONS EXPLAINED

-R
operate on files and directories recursively


创建 MySQL服务器 授权表。 执行脚本 mysql_install_db 作为 mysql 用户。

# scripts/mysql_install_db --user=mysql
OPTIONS EXPLAINED

--user
The login username to use for running mysqld. Files and directories created by mysqld will be owned by this user. You must be root to use this option. By default mysqld runs using your current login name and files and directories that it creates will be owned by you.


改变后的所有者和组 /usr/local/mysql/ 根目录的内容。

# chown -R root .
OPTIONS EXPLAINED

-R
operate on files and directories recursively


改变的主人 /usr/local/mysql/ 目录 mysql

# chown -R mysql data
OPTIONS EXPLAINED

-R
operate on files and directories recursively

数据目录已经是集团将所有权 mysql 。 使用这个命令组和所有者 /usr/local/mysql/data/ 目录将被设置为 mysql


删除权限 集团 别人 /usr/local/mysql/data/ 目录中。 所以,只有 mysql 将可以访问它。

# chmod -R go-rwx data
OPTIONS EXPLAINED

-R
operate on files and directories recursively

go-rwx
Remove read,write & execute permissions for group & others


设置配置文件
默认的配置文件副本 my-default.cnf /etc/ 目录,重命名它 my.cnf

# cp support-files/my-default.cnf /etc/my.cnf

打开 MySQL服务器 配置文件 /etc/my.cnf 。 我们必须进行某些更改为服务器正常工作。 注意:如果你已经改变了MySQL服务器安装目录或数据目录的位置 MySQL的默认安装目录服务器 /usr/local/mysql/ 。 和MySQL服务器的默认数据目录 /usr/local/mysql/data/ 。 如果你有改变其中任何一个,确保适当的更改的值 basedir datadir

设置MySQL用户 MySQL服务器 默认情况下运行在用户根。 运行 MySQL服务器 作为根用户是不安全的,所以不是明智的。 所以将 MySQL服务器 作为标准的用户运行 mysql 。 下方的 (mysqld) 部分添加一个新行,如下所示。

user = mysql

配置MySQL服务器的IP绑定 MySQL服务器 默认绑定到给定系统的所有接口上的所有IP地址。 如果我们想要 MySQL服务器 只绑定在一个给定的IP地址,我们必须配置如下。 下 (mysqld) 节中,添加以下的IP地址你想绑定。 注意: 取代 192.168.0.100 你的机器的IP地址。

bind-address = 192.168.0.100

这使得 MySQL服务器 192.168.0.100绑定到IP地址。 注意:如果我们希望MySQL服务器绑定一组选定的接口,我们可以离开MySQL服务器的默认行为,与防火墙我们不想绑定的接口。

初始化MySQL服务器授权表。 执行mysqld_safe mysql用户。

# mysqld_safe --user=mysql &
OPTIONS EXPLAINED

--user
Run the mysqld server as the user having the name user_name or the numeric user ID user_id. (“User” in this context refers to a system login account, not a MySQL user listed in the grant tables.)

mysqld_safe 推荐的方式开始吗 mysqld 服务器 UNIX 网络 。 它初始化的mysql表包含特权授予决定允许用户连接到服务器。 mysqld_safe 还增加了一些安全功能,如重新启动服务器时发生错误和日志记录错误日志文件运行时信息。 注意: &命令,命令移动背景和给我们的终端进行进一步的工作。 如果命令后吐出了标准输出服务正在运行,只是新闻 ctrl - c 或关闭终端,打开一个新的。

设置MySQL服务器服务 复制 MySQL服务器 守护进程的启动/停止脚本 mysql.server /etc/rc.d/init.d/ 目录,重命名它 mysql

# cp -v support-files/mysql.server /etc/rc.d/init.d/mysql
OPTIONS EXPLAINED

-v
explain what is being done


添加 mysql 作为一个系统V init服务。

# chkconfig --add mysql
OPTIONS EXPLAINED

--add
This option adds a new service for management by chkconfig.  When a new service is added, chkconfig ensures that the service has either a start  or  a kill entry in every runlevel. If any runlevel is missing such an entry, chkconfig creates the appropriate entry as specified by the default values in the init script. Note that default entries in LSB-delimited  ’INIT  INFO’  sections  take  precedence  over  the default  runlevels  in  the  initscript; if any Required-Start or Required-Stop entries are present, the start and stop priorities of the script will be adjusted to account for these dependencies.

这个选项增加了 mysql Sys V init服务管理 chkconfig 。 当添加一个新的服务, chkconfig 确保服务启动或杀死进入每一个级别。 如果任何运行级别缺失这样一个条目, chkconfig 创建适当的条目中指定的默认值初始化脚本。 chkconfig 也为我们创建以下softlinks mysql 脚本对应的运行级别目录。 /etc/rc.d/rc0.d/K36mysql /etc/rc.d/rc1.d/K36mysql /etc/rc.d/rc2.d/S64mysql /etc/rc.d/rc3.d/S64mysql /etc/rc.d/rc4.d/S64mysql /etc/rc.d/rc5.d/S64mysql /etc/rc.d/rc6.d/K36mysql

注意: K36mysql - K代表杀死。36意味着mysql将死于第36个订单。 这是用于运行级0(关闭),1(单用户模式),6(重启)。 所以 mysql 服务将在运行级0、1和6。 S64mysql 64年代代表开始。意味着mysql将在64开始订单。 这是用于GUI /自定义运行级2、3、4、5。 所以 mysql 服务将开始在运行级2、3、4和5。


最后,启动 mysql 服务。

# service mysql start
OPTIONS EXPLAINED

start
starts the specified service

6)安装缺少的依赖关系 不过,有一件事未完成的- MySQL基准套件 MySQL服务器 附带的 MySQL基准套件 ,这是安装在 /usr/local/mysql/sql-bench/ 。 它可以基准 MySQL服务器 和判断给定实现执行好与坏。 都写在基准脚本 Perl 并使用 DBI 模块访问数据库服务器。 所以我们需要以下运行 MySQL基准套件 - - - - - - Perl , DBI DBD::mysql 。 上面的三个, Perl DBI 除了安装 DBD::mysql 。 我们没有安装 DBD::mysql 在安装之前 MySQL服务器 ,因为 DBD::mysql 需要 MySQL服务器 出现之前的安装。 安装 DBD::mysql ,按照 在这里安装说明 注意: 阅读更多关于 DBI libdbi

7)安装检查 安装位置 /usr/local/mysql/

PID文件 语法: /usr/local/mysql/data/HOSTNAME.pid 例子: /usr/local/mysql/data/example.com.pid

套接字文件 / tmp / mysql.sock

服务文件 /etc/rc.d/init.d/mysql

缺省端口 3306年

可执行文件 列出并解释了

配置文件 列出并解释了

日志文件 列出并解释了


获取服务器状态信息
显示MySQL服务的状态

# service mysql status

显示mysqld守护进程的状态

# mysqladmin -u root -p ping

显示服务器的状态变量

# mysqladmin -u root -p status

显示服务器的状态变量和它们的值

# mysqladmin -u root -p extended-status



在活动服务器线程获取信息
显示活动服务器线程的列表

# mysqladmin -u root -p processlist

显示充满processlist活动服务器线程的列表

# mysqladmin -u root -p -v processlist



获得信息在服务器变量
显示服务器系统变量和它们的值的列表

# mysqladmin -u root -p variables



获取服务器版本信息

# mysqladmin -u root -p version
原文地址:https://www.cnblogs.com/endv/p/4532237.html