700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > LNMP架构环境搭建之mysql源码编译安装

LNMP架构环境搭建之mysql源码编译安装

时间:2021-06-11 03:34:24

相关推荐

LNMP架构环境搭建之mysql源码编译安装

Mysql

MySQL是一个开源的数据库,在互联网行业应用的很广泛,下面来记录一下从源码编译安装的步骤,当然,MySQL也有其他安装方式,比如,使用yum下载安装rpm包,或者二进制方式安装,如果机器比较多,可以自己搭建yum源,然后定制rpm包,这样更方便于使用ssh多机自动安装

这里源码安装的mysql版本为5.7.11,使用cmake编译安装,所需安装包的下载链接:cmake and mysql

下面开始记录安装步骤吧

编译安装

//解压 mysql 压缩包//yum 安装 cmake 的 rpm 包[root@server1 ~]# lscmake-2.8.12.2-4.el6.x86_64.rpm mysql-boost-5.7.11.tar.gz[root@server1 ~]# tar zxf mysql-boost-5.7.11.tar.gz [root@server1 ~]# lscmake-2.8.12.2-4.el6.x86_64.rpm mysql-5.7.11 mysql-boost-5.7.11.tar.gz[root@server1 ~]# yum install -y cmake-2.8.12.2-4.el6.x86_64.rpm //进入到mysql解压后的目录下,进行cmake,参数祥见cmake --help//添加所需要的内容,此处添加的内容代表意思如下:/*-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql #安装目录-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data #数据库存放目录-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock #Unix socket 文件路径-DWITH_MYISAM_STORAGE_ENGINE=1 #安装myisam存储引擎 -DWITH_INNOBASE_STORAGE_ENGINE=1 #安装innodb存储引擎-DDEFAULT_CHARSET=utf8 #使用utf8字符-DDEFAULT_COLLATION=utf8_general_ci #校验字符-DEXTRA_CHARSETS=all #安装所有扩展字符集*/[root@server1 ~]# cd mysql-5.7.11/[root@server1 mysql-5.7.11]# lsboost config.h.cmake extralibeventmysysscripts testclientsBUILD configure.cmakeinclude libmysqlmysys_ssl sql unittestclientCOPYING INSTALL libmysqld packaging sql-commonVERSIONcmake dbug INSTALL-SOURCE libservices pluginstorage vioCMakeLists.txt Docs libbinlogeventsmanREADMEstrings wincmd-line-utils Doxyfile-perfschema libbinlogstandalone mysql-test regexsupport-files zlib

[root@server1 mysql-5.7.11]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/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 必须解决,Warning 可以忽略,最好是解决

这里由于我是直接用的新的虚拟机搭建LNMP架构,我将我遇到的Error列出如下(附解决方法):

问题

解决

问题

问题

解决

问题

解决

[root@server1 mysql-5.7.11]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/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/

cmake 完成后

[root@server1 mysql-5.7.11]# make

[root@server1 mysql-5.7.11]# make install

简单初始化配置

[root@server1 mysql-5.7.11]# cd[root@server1 ~]# ls /usr/local/lnmp/mysql/support-files/magic my-f mysqld_multi.server mysql-log-rotate mysql.server[root@server1 ~]# cp /usr/local/lnmp/mysql/support-files/my-f /etc/f cp: overwrite `/etc/f'? y[root@server1 ~]# vim /etc/f ##修改内容如下(也可不做任何修改)18 basedir = /usr/local/lnmp/mysql19 datadir = /usr/local/lnmp/mysql/data20 port = 330621 # server_id = .....22 socket = /usr/local/lnmp/mysql/data/mysql.sock[root@server1 ~]# cp /usr/local/lnmp/mysql/support-files/mysql.server /etc/init.d/mysqld[root@server1 ~]# ll /usr/local/lnmp/mysqltotal 56drwxr-xr-x 2 root root 4096 Aug 5 10:17 bin-rw-r--r-- 1 root root 17987 Feb 2 COPYINGdrwxr-xr-x 2 root root 4096 Aug 5 10:16 docsdrwxr-xr-x 3 root root 4096 Aug 5 10:16 includedrwxr-xr-x 4 root root 4096 Aug 5 10:17 libdrwxr-xr-x 4 root root 4096 Aug 5 10:16 mandrwxr-xr-x 10 root root 4096 Aug 5 10:17 mysql-test-rw-r--r-- 1 root root 2478 Feb 2 READMEdrwxr-xr-x 28 root root 4096 Aug 5 10:17 sharedrwxr-xr-x 2 root root 4096 Aug 5 10:17 support-files##添加mysql组、创建mysql用户[root@server1 mysql]# groupadd -g 27 mysql[root@server1 mysql]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/data -s /sbin/nologin mysql[root@server1 ~]# vim ~/.bash_profile 10 PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin[root@server1 ~]# source ~/.bash_profile ##~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,##当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量执行用户的.bashrc文件[root@server1 ~]# cd /usr/local/lnmp/mysql ##进行mysql的初始化[root@server1 mysql]# mysqld --initialize --user=mysql-08-05T03:08:09.684310Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).-08-05T03:08:09.684400Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.-08-05T03:08:09.684405Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.-08-05T03:08:11.964546Z 0 [Warning] InnoDB: New log files created, LSN=45790-08-05T03:08:12.422641Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.-08-05T03:08:12.590273Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c9dcc6d4-985c-11e8-adb3-52540004503d.-08-05T03:08:12.673131Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.-08-05T03:08:12.687518Z 1 [Note] A temporary password is generated for root@localhost: XFdyFIO2A*q%## XFdyFIO2A*q% 最后的这个字符串是初始化后mysql的初始密码[root@server1 mysql]# ls ##初始化后,生成data目录bin COPYING data docs include lib man mysql-test README share support-files

测试脚本启动

[root@server1 mysql]# /etc/init.d/mysqld startStarting MySQL.. SUCCESS! [root@server1 mysql]# /etc/init.d/mysqld stopShutting down MySQL.. SUCCESS! [root@server1 mysql]#

[root@server1 mysql]# chkconfig --list mysqld ##查看mysql服务是否在开机自启项中service mysqld supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add mysqld')[root@server1 mysql]# ll data/drwxr-x--- 5 mysql mysql 4096 Aug 5 11:10 data[root@server1 mysql]# chgrp root data/ -R ##修改目录data的所在组[root@server1 mysql]# ll data/drwxr-x--- 5 mysql root 4096 Aug 5 11:10 data[root@server1 mysql]# /etc/init.d/mysqld startStarting MySQL. SUCCESS!

进入安全配置向导

这里列出我的选择,你选择你需要的

[root@server1 mysql]# mysql_secure_installationSecuring the MySQL server deployment.Enter password for user root: ##输入刚才初始化的密码(复制粘贴)The existing password for the user account root has expired. Please set a new password.##修改密码New password: Re-enter new password: VALIDATE PASSWORD PLUGIN can be used to test passwordsand improve security. It checks the strength of passwordand allows the users to set only those passwords which aresecure enough. Would you like to setup VALIDATE PASSWORD plugin?Press y|Y for Yes, any other key for No: ##是否使用VALIDATE PASSWORD PLUGIN,这个看自己Using existing password for root.Change the password for root ? ((Press y|Y for Yes, any other key for No) : ... skipping.By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : y##是否删除匿名用户,生产环境建议删除Success.Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y ##是否禁止root远程登录Success.By default, MySQL comes with a database named 'test' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y##是否删除test数据库- Dropping test database...Success.- Removing privileges on test database...Success.Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y##是否重新加载权限表Success.All done!

测试mysql的使用

[root@server1 mysql]# mysql -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 5Server version: 5.7.11 Source distributionCopyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> SHOW DATABASES;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys|+--------------------+4 rows in set (0.00 sec)mysql> QUITBye[root@server1 mysql]#

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。