Linux 安裝 mysql5.7.7-64位

必須的資源包下載地址:
1.http://download.csdn.net/download/lzq123_1/9333777   

gmock-1.6.0.zip

2.http://download.csdn.net/detail/lzq123_1/9333741

cmake-3.2.1.tar.gz  

3.http://download.csdn.net/detail/lzq123_1/9333733

boost_1_57_0.tar.gz2 

4.http://download.csdn.net/detail/lzq123_1/9333651

bison-3.0.tar.gz  

5.http://download.csdn.net/detail/lzq123_1/9333613

mysql-5.7.7-rc.tar.gz  

以上5個資源必須版本一致,然後並且按下面的方法進行設置,一定100%成功,下面的安裝方法已經經過測試。

1 創建mysql用戶和用戶組,並下載MySQL5.7.7版本
#######新建mysql用戶和mysql組
[root@typecodes ~]# groupadd -r mysql && useradd -r -g mysql -s /bin/false -M mysql 
[root@typecodes ~]# wget -c http://git.typecodes.com/libs/mysql/mysql-5.7.7-rc.tar.gz
[root@typecodes ~]# md5sum mysql-5.7.7-rc.tar.gz        [MD5校驗]
36a96021a93ca236e76f5c90ae19cd44  mysql-5.7.7-rc.tar.gz
######開始解壓MySQL5.7.7
[root@typecodes ~]# tar -zxf mysql-5.7.7-rc.tar.gz && cd mysql-5.7.7-rc
######下載gmock:google的c++mock框架,從mysql 5.6開始支持
[root@typecodes mysql-5.7.7-rc]# wget -c http://git.typecodes.com/libs/ccpp/gmock-1.6.0.zip
######將其解壓到MySQL5.7.7的source_downloads目錄下
[root@typecodes mysql-5.7.7-rc]# unzip gmock-1.6.0.zip -d source_downloads
2 下載編譯MySQL5.7.7rc時需要的工具
需要下載CMake編譯器、Boost庫、ncurses庫和GNU分析器生成器bison這4種工具。經過自己的測試發現,MySQL5.7.7rc編譯時所需要的Boost庫只能是boost 1.57.0版本,低於或者高於這個版本的都會編譯失敗!
#######CMake編譯工具
[root@typecodes ~]# wget -c http://git.typecodes.com/libs/ccpp/cmake-3.2.1.tar.gz
[root@typecodes ~]# tar -zxf cmake-3.2.1.tar.gz && cd cmake-3.2.1
[root@typecodes cmake-3.2.1]# ./configure 
[root@typecodes cmake-3.2.1]# make && make install  [默認安裝路徑是/usr/local/bin]
[root@typecodes cmake-3.2.1]# cmake --version       [查看cmake版本]
cmake version 3.2.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@typecodes cmake-3.2.1]# cd ~ && rm -rf cmake-3.2.1*

#######Ncurses:提供功能鍵定義(快捷鍵),屏幕繪製以及基於文本終端的圖形互動功能的動態庫。
[root@typecodes ~]# yum -y install ncurses-devel

#######bison:GNU分析器生成器
[root@typecodes ~]# wget -c http://git.typecodes.com/libs/ccpp/bison-3.0.tar.gz
[root@typecodes ~]# tar -zxf bison-3.0.tar.gz && cd bison-3.0/ && ./configure
[root@typecodes bison-3.0]# make && make install
[root@typecodes bison-3.0]# cd ~ && rm -rf bison-3.0*

#######Boost庫:一個開源可移植的C++庫,是C++標準化進程的開發引擎之一
[root@typecodes ~]# wget -c http://git.typecodes.com/libs/ccpp/boost_1_57_0.tar.bz2
[root@typecodes ~]# tar -jxf boost_1_57_0.tar.bz2 && cd boost_1_57_0/
[root@typecodes boost_1_57_0]# ./bootstrap.sh
[root@typecodes boost_1_57_0]# ./b2 stage threading=multi link=shared
[root@typecodes boost_1_57_0]# ./b2 install threading=multi link=shared
[root@typecodes boost_1_57_0]# cd ~ && rm -rf boost_1_57_0*
3 開始進行MySQL5.7.7rc編譯前的配置
準備工作做好後,就開始正式配置MySQL5.7.7rc的安裝明細了。注意,操作時一定要先把下面反斜槓“\”後面添加的註釋文字去掉!!!
######使用cmake命令,開始編譯MySQL5.7.7rc
[root@typecodes mysql-5.7.7-rc]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql  \              [MySQL安裝的根目錄]
-DMYSQL_DATADIR=/mydata/mysql/data  \                   [MySQL數據庫文件存放目錄]
-DSYSCONFDIR=/etc \                                     [MySQL配置文件所在目錄]
-DMYSQL_USER=mysql \                                    [MySQL用戶名]      
-DWITH_MYISAM_STORAGE_ENGINE=1 \                        [MySQL的數據庫引擎]
-DWITH_INNOBASE_STORAGE_ENGINE=1 \                      [MySQL的數據庫引擎]
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \                       [MySQL的數據庫引擎]
-DWITH_MEMORY_STORAGE_ENGINE=1 \                        [MySQL的數據庫引擎]
-DWITH_READLINE=1 \                                     [MySQL的readline library]
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \           [MySQL的通訊目錄]
-DMYSQL_TCP_PORT=3306 \                                 [MySQL的監聽端口]
-DENABLED_LOCAL_INFILE=1 \                              [啓用加載本地數據]
-DENABLE_DOWNLOADS=1 \                                  [編譯時允許自主下載相關文件]
-DWITH_PARTITION_STORAGE_ENGINE=1  \
-DEXTRA_CHARSETS=all \                                  [使MySQL支持所有的擴展字符]
-DDEFAULT_CHARSET=utf8 \                                [設置默認字符集爲utf8]
-DDEFAULT_COLLATION=utf8_general_ci \                   [設置默認字符校對]
-DWITH_DEBUG=0 \                                        [禁用調試模式]
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \                             [通訊時支持ssl協議]
-DWITH_ZLIB:STRING=bundled                              [允許使用zlib library]
可以直接運行的:
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql  \
-DMYSQL_DATADIR=/mydata/mysql/data  \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1  \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled


運行結果:


4 開始編譯和安裝MySQL5.7.7rc
[root@typecodes mysql-5.7.7-rc]# make && make install
make執行完的結果圖:


5 查看編譯成功後的MySQL安裝目錄
使用命令查看MySQL的安裝目錄/usr/local/mysql/下面是否生成了相關目錄文件(最重要的當然是bin、sbin和lib目錄)。如果lib目錄下面沒有生成如圖所示的.so動態庫文件和.a靜態庫文件,那麼說明安裝不成功(即使成功了也可能會導致php進程無法找到mysql的相關庫文件)。

6 開始設置MySQL的配置文件my.cnf
[root@typecodes mysql]# mv /etc/my.cnf /etc/my.cnfbak
[root@typecodes mysql]# vim  /etc/my.cnf
my.cnf的內容爲:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[client]
port=3306
socket=/var/run/mysql/mysql.sock

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
user = mysql
basedir = /usr/local/mysql
datadir = /mydata/mysql/data
port=3306
server-id = 1
socket=/var/run/mysql/mysql.sock

character-set-server = utf8
log-error = /var/log/mysql/error.log
pid-file = /var/log/mysql/mysql.pid
general_log = 1
skip-name-resolve
#skip-networking
back_log = 300

max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128 
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M

read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 28M
key_buffer_size = 4M

thread_cache_size = 8

query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M

ft_min_word_len = 4

log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30


performance_schema = 0
explicit_defaults_for_timestamp

#lower_case_table_names = 1



myisam_sort_buffer_size = 8M
myisam_repair_threads = 1

interactive_timeout = 28800
wait_timeout = 28800


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES 

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
7 添加mysql的環境變量

將MySQL編譯生成的bin目錄添加到當前Linux系統的環境變量中

[root@typecodes mysql]# echo -e '\n\nexport PATH=/usr/local/mysql/bin:$PATH\n' >> /etc/profile && source /etc/profile
8 創建MySQL數據庫文件的存放路徑以及相關安全配置

在Linux主機上創建一個目錄/mydata/mysql/data,用於存放MySQL的數據庫文件。同時設置其用戶和用戶組爲之前創建的mysql,權限爲777。這樣其它用戶是無法進行讀寫的,儘量保證數據庫的安全。

[root@typecodes ~]# mkdir -p /mydata/mysql/data && chown -R root:mysql /usr/local/mysql
[root@typecodes mysql]# chown -R mysql:mysql /mydata/mysql/data
[root@typecodes mysql]# chmod -R go-rwx /mydata/mysql/data
9 初始化MySQL自身的數據庫

在MySQL安裝目錄的\bin\路徑下,執行mysqld命令,初始化MySQL自身的數據庫。

######參數user表示用戶,basedir表示mysql的安裝路徑,datadir表示數據庫文件存放路徑
[root@typecodes bin]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/mysql/data

執行完後,可以通過[root@typecodes mysql]# ls -lrt /mydata/mysql/data/命令查看是否生成了MySQL自身的數據庫文件。



10 創建MySQL日誌存放目錄以及設置開機啓動

下面配置的MySQL日誌存放目錄以及權限都是根據前面my.cnf文件寫的,也就是兩者需要保持一致。

[root@typecodes ~]# mkdir -p /var/run/mysql && mkdir -p /var/log/mysql
[root@typecodes ~]# chown -R mysql:mysql /var/log/mysql && chown -R mysql:mysql /var/run/mysql
######配置開機自啓動
[root@typecodes mysql]# cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
[root@typecodes mysql]# chmod +x /etc/init.d/mysqld     #增加可執行權限
[root@typecodes mysql]# chkconfig --add mysql       #添加到sysV服務
[root@typecodes mysql]# chkconfig mysqld on
11 啓動MySQL服務

在完成上面的操作後,就可以正式使用MySQL服務了。啓動MySQL進程服務的命令如下:

[root@typecodes mysql]# mysqld_safe --user=mysql --datadir=/mydata/mysql/data --log-error=/var/log/mysql/error.log &        [直接回車]
[1] 10274
150513 21:28:16 mysqld_safe Logging to '/var/log/mysql/error.log'.
150513 21:28:16 mysqld_safe Starting mysqld daemon with databases from /mydata/mysql/data

######上面這條命令會在後臺繼續執行,所以直接回車並執行下面這條命令
[root@typecodes mysql]# service mysqld start
Starting MySQL.[  OK  ]                 [啓動成功]
[root@typecodes mysql]# 

然後使用下面這命令ps -ef | grep mysqlnetstat -tunpl | grep 3306查看MySQL服務進程和端口監聽情況:

查看MySQL服務進程和端口監聽情況

12 初始化MySQL數據庫的root用戶密碼

和Oracle數據庫一樣,MySQL數據庫也默認自帶了一個root用戶(這個和當前Linux主機上的root用戶是完全不搭邊的),我們在設置好MySQL數據庫的安全配置後初始化root用戶的密碼。配置過程中,一路輸入y就行了。這裏只說明下MySQL5.7.7rc版本中,用戶密碼策略分成低級LOW、中等MEDIUM和超強STRONG三種,推薦使用中等MEDIUM級別!

[root@typecodes mysql]# mysql_secure_installation
............省略前面的過程............
Press y|Y for Yes, any other key for No: y   【需要修改密碼,所以輸入y】

There are three levels of password validation policy:

LOW    Length >= 8     【只需要長度大於或等於8】
MEDIUM Length >= 8, numeric, mixed case, and special characters   【還需要包含數字、大小寫和類似於@#%等特殊字符】
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file    【還需要包含字典文件】
............省略剩下的過程............
13 將MySQL數據庫的動態鏈接庫共享至系統鏈接庫

一般MySQL數據庫還會被類似於PHP等服務調用,所以我們需要將MySQL編譯後的lib庫文件添加至當前Linux主機鏈接庫/etc/ld.so.conf.d/下,這樣MySQL服務就可以被其它服務調用了。

[root@typecodes lib]# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
[root@typecodes lib]# ldconfig          [使生效]
[root@typecodes lib]# ldconfig -v |grep mysql       [查看效果]
ldconfig: Can't stat /libx32: No such file or directory
ldconfig: Path `/usr/lib' given more than once
ldconfig: Path `/usr/lib64' given more than once
ldconfig: Can't stat /usr/libx32: No such file or directory
/usr/lib64/mysql:
        libmysqlclient.so.18 -> libmysqlclient.so.18.0.0
/usr/local/mysql/lib:
        libmysqlclient.so.20 -> libmysqlclient_r.so.20.0.0
14 創建其它MySQL數據庫用戶

使用MySQL數據庫root管理員用戶登錄MySQL數據庫後,可以管理數據庫和其他用戶了。這裏演示創建一個名爲typecodes的MySQL用戶(密碼爲@typecodes2014.com)和一個名爲typecodes的數據庫。

[root@typecodes mysql]# mysql -uroot -p密碼

######登錄成功後,創建typecodes數據庫,並設置字符集和字符校
mysql> CREATE DATABASE `typecodes` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)

######創建名爲typecodes用戶,並讓它擁有typecodes數據庫所有的權限
mysql> grant all privileges on typecodes.* to typecodes@localhost identified by '@typecodes2014.com';
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;            [創建完畢,root用戶退出]

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章