MySQL是一個開源的數據庫,在互聯網行業應用的很廣泛,下面來記錄一下從源碼編譯安裝的步驟,當然,MySQL也有其他安裝方式,比如,使用yum下載安裝rpm包,或者二進制方式安裝,如果機器比較多,可以自己搭建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
//進入到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]# 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]# 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 ##修改內容如下(也可不做任何修改)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 510:17 bin
-rw-r--r-- 1 root root 17987 Feb 2 2016 COPYING
drwxr-xr-x 2 root root 4096 Aug 510:16 docs
drwxr-xr-x 3 root root 4096 Aug 510:16 include
drwxr-xr-x 4 root root 4096 Aug 510:17 lib
drwxr-xr-x 4 root root 4096 Aug 510:16 man
drwxr-xr-x 10 root root 4096 Aug 510:17 mysql-test
-rw-r--r-- 1 root root 2478 Feb 2 2016 README
drwxr-xr-x 28 root root 4096 Aug 510:17 share
drwxr-xr-x 2 root root 4096 Aug 510: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=mysql2018-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 notset.
2018-08-05T03:08:11.964546Z 0 [Warning] InnoDB: New log files created, LSN=457902018-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 isthefirsttimethat this server has been started. Generating a new UUID: c9dcc6d4-985c-11e8-adb3-52540004503d.
2018-08-05T03:08:12.673131Z 0 [Warning] Gtid table isnot 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 startStartingMySQL.. 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 isnot referenced in any runlevel (run 'chkconfig --add mysqld')
[root@server1 mysql]# ll data/
drwxr-x--- 5 mysql mysql 4096 Aug 511:10 data
[root@server1 mysql]# chgrp root data/ -R ##修改目錄data的所在組
[root@server1 mysql]# ll data/
drwxr-x--- 5 mysql root 4096 Aug 511: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: ##輸入剛才初始化的密碼(復制粘貼)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 tosetonly those passwords which are
secure enough. Would you liketo setup VALIDATE PASSWORD plugin?Press y|Y for Yes, any other keyforNo:
##是否使用VALIDATE PASSWORD PLUGIN,這個看自己
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other keyforNo) : ... skipping.
Bydefault, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without havingto have
a user account created for them. This is intended onlyfor
testing, andto 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 keyforNo) : y
##是否刪除匿名用戶,生產環境建議刪除
Success.Normally, root should only be allowed toconnectfrom'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 keyforNo) : y
##是否禁止root遠程登錄
Success.Bydefault, MySQL comes with a database named 'test' that
anyone can access. This is also intended onlyfor testing,
and should be removed before moving into a production
environment.Remove test databaseand access to it? (Press y|Y for Yes, any other keyforNo) : y
##是否刪除test數據庫- Dropping test database...
Success.- Removing privilegeson 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 keyforNo) : y
##是否重新加載權限表
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]#