日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

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

發(fā)布時間:2025/3/19 数据库 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LNMP架构环境搭建之mysql源码编译安装 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Mysql

MySQL是一個開源的數(shù)據(jù)庫,在互聯(lián)網(wǎng)行業(yè)應(yīng)用的很廣泛,下面來記錄一下從源碼編譯安裝的步驟,當(dāng)然,MySQL也有其他安裝方式,比如,使用yum下載安裝rpm包,或者二進(jìn)制方式安裝,如果機器比較多,可以自己搭建yum源,然后定制rpm包,這樣更方便于使用ssh多機自動安裝
這里源碼安裝的mysql版本為5.7.11,使用cmake編譯安裝,所需安裝包的下載鏈接:cmake and mysql
下面開始記錄安裝步驟吧

  • 編譯安裝

//解壓 mysql 壓縮包 //yum 安裝 cmake 的 rpm 包 [root@server1 ~]# ls cmake-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 ~]# ls cmake-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 //進(jìn)入到mysql解壓后的目錄下,進(jìn)行cmake,參數(shù)祥見cmake --help //添加所需要的內(nèi)容,此處添加的內(nèi)容代表意思如下: /* -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql #安裝目錄 -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data #數(shù)據(jù)庫存放目錄 -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 #安裝所有擴(kuò)展字符集 */ [root@server1 ~]# cd mysql-5.7.11/ [root@server1 mysql-5.7.11]# ls boost config.h.cmake extra libevent mysys scripts testclients BUILD configure.cmake include libmysql mysys_ssl sql unittest client COPYING INSTALL libmysqld packaging sql-common VERSION cmake dbug INSTALL-SOURCE libservices plugin storage vio CMakeLists.txt Docs libbinlogevents man README strings win cmd-line-utils Doxyfile-perfschema libbinlogstandalone mysql-test regex support-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過程中出現(xiàn)的Error 必須解決,Warning 可以忽略,最好是解決
這里由于我是直接用的新的虛擬機搭建LNMP架構(gòu),我將我遇到的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-default.cnf mysqld_multi.server mysql-log-rotate mysql.server [root@server1 ~]# cp /usr/local/lnmp/mysql/support-files/my-default.cnf /etc/my.cnf cp: overwrite `/etc/my.cnf'? y [root@server1 ~]# vim /etc/my.cnf ##修改內(nèi)容如下(也可不做任何修改)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/mysql total 56 drwxr-xr-x 2 root root 4096 Aug 5 10:17 bin -rw-r--r-- 1 root root 17987 Feb 2 2016 COPYING drwxr-xr-x 2 root root 4096 Aug 5 10:16 docs drwxr-xr-x 3 root root 4096 Aug 5 10:16 include drwxr-xr-x 4 root root 4096 Aug 5 10:17 lib drwxr-xr-x 4 root root 4096 Aug 5 10:16 man drwxr-xr-x 10 root root 4096 Aug 5 10:17 mysql-test -rw-r--r-- 1 root root 2478 Feb 2 2016 README drwxr-xr-x 28 root root 4096 Aug 5 10:17 share drwxr-xr-x 2 root root 4096 Aug 5 10:17 support-files ##添加mysql組、創(chuàng)建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信息, ##當(dāng)用戶登錄時,該文件僅僅執(zhí)行一次!默認(rèn)情況下,他設(shè)置一些環(huán)境變量執(zhí)行用戶的.bashrc文件 [root@server1 ~]# cd /usr/local/lnmp/mysql ##進(jìn)行mysql的初始化 [root@server1 mysql]# mysqld --initialize --user=mysql 2018-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). 2018-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. 2018-08-05T03:08:09.684405Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set. 2018-08-05T03:08:11.964546Z 0 [Warning] InnoDB: New log files created, LSN=45790 2018-08-05T03:08:12.422641Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-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. 2018-08-05T03:08:12.673131Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2018-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 start Starting MySQL.. SUCCESS! [root@server1 mysql]# /etc/init.d/mysqld stop Shutting down MySQL.. SUCCESS! [root@server1 mysql]# [root@server1 mysql]# chkconfig --list mysqld ##查看mysql服務(wù)是否在開機自啟項中 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 start Starting MySQL. SUCCESS!
  • 這里列出我的選擇,你選擇你需要的

[root@server1 mysql]# mysql_secure_installation Securing the MySQL server deployment.Enter password for user root: ##輸入剛才初始化的密碼(復(fù)制粘貼)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 passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure 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 have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : y ##是否刪除匿名用戶,生產(chǎn)環(huán)境建議刪除 Success.Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y ##是否禁止root遠(yuǎn)程登錄 Success.By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y ##是否刪除test數(shù)據(jù)庫- Dropping test database... Success.- Removing privileges on test database... Success.Reloading the privilege tables will ensure that all changes made so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y ##是否重新加載權(quán)限表 Success.All done!
  • 測試mysql的使用

[root@server1 mysql]# mysql -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.11 Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.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> QUIT Bye [root@server1 mysql]#

總結(jié)

以上是生活随笔為你收集整理的LNMP架构环境搭建之mysql源码编译安装的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。