mysql + php + nginx (LNMP)源码编译安装

mysql源码编译安装

官网下载mysql安装包 : mysql-boost-5.7.22.tar.gz

mysql源码安装需要使用c++的boost库,而mysql-boost压缩包自带boost库,不需要在下载boost安装包,mysql在3.8版本以后使用cmake跨平台工具预编译源码,用于设置mysql的编译参数;bison 一种linux下的c/c++语法分析器;

###解压压缩包编译安装环境###
[root@serevr1 ~]# tar -zxf mysql-boost-5.7.11.tar.gz 
[root@serevr1 ~]# cd mysql-5.7.11/
[root@serevr1 mysql-5.7.11]# du -sh    ##查看数据库解压包大小
521M    .
[root@serevr1 mysql-5.7.11]# ls
boost            dbug                 libevent     plugin         testclients
BUILD            Docs                 libmysql     README         unittest
client           Doxyfile-perfschema  libmysqld    regex          VERSION
cmake            extra                libservices  scripts        vio
CMakeLists.txt   include              man          sql            win
cmd-line-utils   INSTALL              mysql-test   sql-common     zlib
config.h.cmake   INSTALL-SOURCE       mysys        storage
configure.cmake  libbinlogevents      mysys_ssl    strings
COPYING          libbinlogstandalone  packaging    support-files
[root@server1 mysql-5.7.11]# yum install -y cmake
[root@server1 mysql-5.7.11]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data  -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all


##执行编译后报错##
CMake Error at CMakeLists.txt:21 (CMAKE_MINIMUM_REQUIRED):
  CMake 2.8.2 or higher is required.  You are running version 2.6.4
  我们安装的cmake版本过低,需要安装2.8.2版本或者以上
[root@serevr1 ~]# yum update cmake-2.8.12.2-4.el6.x86_64.rpm   
###升级版本再次执行编译,以下列出编译时我遇见的错误
CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found.   Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found.   Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
[root@server1 mysql-5.7.11]# yum install -y gcc gcc-c++

CMake Error at cmake/boost.cmake:81 (MESSAGE):
  You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
 [root@server1 mysql-5.7.11]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data  -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all 
 -DWITH_BOOST=boost/boost_1_59_0/
###boost解压包自带,不知道路径时两次tab补齐
CMake Error at cmake/readline.cmake:64 (MESSAGE):
  Curses library not found.  Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
##提示我们需要删除编译文件CMakeCache.txt,解决相关报错,再次执行编译,后面步骤同以上步骤!
[root@server1 mysql-5.7.11]# rm -fr CMakeCache.txt 
[root@server1 mysql-5.7.11]# yum install -y ncurses-devel 
Make Warning at cmake/bison.cmake:20 (MESSAGE):
  Bison executable not found in PATH
Call Stack (most recent call first):
  libmysqld/CMakeLists.txt:142 (INCLUDE)
[root@server1 mysql-5.7.11]# yum install -y bison
以上就是我编译安装遇见的问题!
make  &&  make install    ##编译环境和安装需要很长时间

####配置文件和启动脚本###
[root@server1 support-files]# pwd
/usr/local/mysql/support-files
[root@server1 support-files]# ls
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@server1 support-files]# file mysql.server 
mysql.server: POSIX shell script text executable    <mysql的启动脚本>
[root@server1 support-files]# cp mysql.server /etc/init.d/mysql
[root@server1 support-files]# mv /etc/my.cnf /etc/my.cnf.bak
<将原来配置配置文件备份,复制模板到改目录>
[root@server1 support-files]# cp my-default.cnf /etc/my.cnf<mysql默认配置文件>


###创建mysql运行的用户mysql###
[root@server1 mysql]# id mysql
id: mysql: No such user
[root@server1 mysql]# groupadd -g 27 mysql
[root@server1 mysql]# useradd -u 27 -g 27 -d /usr/local/mysql/data -M -s /sbin/nologin mysql
[root@server1 mysql]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)

##编辑安装,data数据以及sock文件路径,让其他人知道你的安装目录利于修改##
[root@server1 mysql]# vi /etc/my.cnf
17 # These are commonly set, remove the # and set as required.
18 basedir = /usr/local/mysql
19 datadir = /usr/local/mysql/data
20 port = 3306
21 # server_id = .....
22 socket = /usr/local/mysql/data/mysql.sock

###将mysql的系统文件添加到全局变量和环境下###
[root@server1 bin]# pwd
/usr/local/mysql/bin
[root@server1 bin]# ls
innochecksum                mysql_config               mysqlshow
lz4_decompress              mysql_config_editor        mysqlslap
myisamchk                   mysqld                     mysql_ssl_rsa_setup
myisam_ftdump               mysqld_multi               mysqltest
myisamlog                   mysqld_safe                mysqltest_embedded
myisampack                  mysqldump                  mysql_tzinfo_to_sql
my_print_defaults           mysqldumpslow              mysql_upgrade
mysql                       mysql_embedded             perror
mysqladmin                  mysqlimport                replace
mysqlbinlog                 mysql_install_db           resolveip
mysqlcheck                  mysql_plugin               resolve_stack_dump
mysql_client_test           mysqlpump                  zlib_decompress
mysql_client_test_embedded  mysql_secure_installation
[root@server1 bin]# vim ~/.bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin

export PATH
[root@server1 bin]# source ~/.bash_profile 


###为了数据库的安全,指定data数据其他人可读,其他文件无权限,视情况而定###
[root@server1 mysql]# pwd
/usr/local/mysql
[root@server1 mysql]# chown mysql.mysql .  -R
[root@server1 mysql]# chown root . -R
[root@server1 mysql]# chown mysql data/ -R
[root@server1 mysql]# ll
total 60
drwxr-xr-x  2 root  mysql  4096 Jun 30 01:09 bin
-rw-r--r--  1 root  mysql 17987 Feb  2  2016 COPYING
drwxr-x---  5 mysql mysql  4096 Jun 30 01:37 data
drwxr-xr-x  2 root  mysql  4096 Jun 30 01:09 docs
drwxr-xr-x  3 root  mysql  4096 Jun 30 01:09 include
drwxr-xr-x  4 root  mysql  4096 Jun 30 01:09 lib
drwxr-xr-x  4 root  mysql  4096 Jun 30 01:09 man
drwxr-xr-x 10 root  mysql  4096 Jun 30 01:09 mysql-test
-rw-r--r--  1 root  mysql  2478 Feb  2  2016 README
drwxr-xr-x 28 root  mysql  4096 Jun 30 01:10 share
drwxr-xr-x  2 root  mysql  4096 Jun 30 01:10 support-files

###数据库系统初始化,使用的命令:mysql目录下执行该命令或者使用绝对路径执行!###
[root@server1 mysql]# mysql_install_db 
2018-06-30 01:32:11 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-06-30 01:32:11 [ERROR]   The data directory needs to be specified.
[root@server1 mysql]# mysqld --verbose --help | less  ###查询支持的参数
[root@server1 mysql]# mysqld --initialize --user=mysql
##初始化数据库,以mysql身份运行####
2018-06-29T17:37:00.664303Z 1 [Note] A temporary password is generated for root@localhost: OtgrgPd6;tN(初始化密码)
***

###mysql数据库的安全配置###
[root@server1 mysql]# mysql_secure_installation 
初始化时遇见问题:
ecuring the MySQL server deployment.

Enter password for user root: 
Error: Access denied for user 'root'@'localhost' (using password: YES)
####复制粘贴时初始密码没有对,多试几次####

[root@server1 ~]# mysql_secure_installation

Securing 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值