1. 程式人生 > >MySQL5.7--------基於CentOS6二進制包安裝

MySQL5.7--------基於CentOS6二進制包安裝

mysql dba mysql5.7

1. 背景

* MySQL是一個關系型數據庫管理系統,由瑞典MySQL AB 公司開發,目前屬於 Oracle 旗下產品。MySQL 是最流行的關系型數據庫管理系統之一,在 WEB 應用方面,MySQL是最好的 RDBMS (Relational Database Management System,關系數據庫管理系統) 應用軟件。

* MySQL是一種關系數據庫管理系統,關系數據庫將數據保存在不同的表中,而不是將所有數據放在一個大倉庫內,這樣就增加了速度並提高了靈活性。

* MySQL所使用的 SQL 語言是用於訪問數據庫的最常用標準化語言。MySQL 軟件采用了雙授權政策,分為社區版和商業版,由於其體積小、速度快、總體擁有成本低,尤其是開放源碼這一特點,一般中小型網站的開發都選擇 MySQL 作為網站數據庫。


2. 選擇的理由

* 支持多種平臺[AIX、FreeBSD、HP-UX、Linux、Mac OS、OpenBSD、Solaris、Windows......]

* 支持並提供多語言API

* 開源,采用了 GPL協議,可以修改源碼來開發自己的 MySQL 系統

* 支持標準SQL語句

* 支持多種存儲引擎

* 使用廣泛 [ 全球top20網站除微軟的Live和Bing之外全部應用MySQL ]

技術分享


3. MySQL安裝方式

* 二制包安裝

* 源碼編譯安裝

* 平臺安裝包,如rpm包[centos,redhat]或deb[debian,ubuntu]包


4. 環境 [關閉selinux]

[[email protected] ~]# cat /etc/redhat-release 
CentOS release 6.9 (Final)

[[email protected] ~]# uname -r
2.6.32-642.3.1.el6.x86_64

[[email protected] ~]# hostname
MySQL

[[email protected]
/* */ ~]# getenforce Disabled


5. 安裝 [ MySQL 5.7的安裝方式與MySQL 5.5/5.6不勁相同 ]

* 下載 MySQL5.7 二進制包 [ 推薦從MySQL官方下載 ]

[[email protected] ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz


* 解壓 MySQL 5.7 二進制包

[[email protected] ~]# tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz


* 移動 MySQL 5.7 二進制包

[[email protected] ~]# mv mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/


* 創建軟鏈接

[[email protected] ~]# ln -s /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql


* 創建 mysql 用戶

[[email protected] ~]# useradd -r -s /sbin/nologin mysql


* 創建 MySQL 數據存放目錄

[[email protected] ~]# mkdir -vp /data/mysql_data
mkdir: created directory `/data‘
mkdir: created directory `/data/mysql_data‘


* 在 MySQL 二進制包目錄中創建 mysql-files 目錄 [MySQL 數據導入/導出數據專放目錄]

[[email protected] ~]# mkdir -v /usr/local/mysql/mysql-files
mkdir: created directory `/usr/local/mysql/mysql-files‘


* 修改 MySQL 二進制包目錄的所屬用戶與所屬組

[[email protected] ~]# chown root.mysql -R /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64


* 修改 MySQL 數據目錄與 數據導入/導出專放目錄的所屬用戶與所屬組

[[email protected] ~]# chown mysql.mysql /usr/local/mysql/mysql-files /data/mysql_data


* 重命名不使用系統自帶 MySQL 配置文件 /etc/my.cnf [ debian類系統在 /etc/mysql/my.cnf ]

[[email protected] ~]# mv /etc/my.cnf{,.old}


* 初始化 [ 初始化完成後會自帶隨機密碼在輸出日誌中 ]

* 版本小於MySQL 5.7.6 [ < 5.7.6 ]

[[email protected] ~]# /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data

* 版本大於或等於MySQL 5.7.6 [ >= 5.7.6 ]

   * 初始化 並指定基本目錄與數據存放目錄

[[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data 
2017-06-23T20:13:52.827475Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-06-23T20:13:57.684349Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-06-23T20:13:58.435803Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-06-23T20:13:58.525266Z 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: 7d8f2b79-5850-11e7-9dab-000c29f0b169.
2017-06-23T20:13:58.538505Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2017-06-23T20:13:58.543606Z 1 [Note] A temporary password is generated for [email protected]: Z91g%.6d&fay

   * 開啟 SSL 連接

[[email protected] ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --user=mysql --basedir=/usr/local/mysql \

6. 創建啟動腳本

* 復制啟動腳本到service 服務管理目錄下[ /etc/init.d ]

[[email protected] ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld


* 修改mysql啟動腳本 [ /et/init.d/mysqld ]

basedir=    ==> basedir=/usr/local/mysql
datadir=    ==> datadir=/data/mysql_data


* 添加腳本執行權限

[[email protected] ~]# chmod +x /etc/init.d/mysqld


* 添加進service服務管理

[[email protected] ~]# chkconfig --add mysqld


7. 服務啟動測試

* 啟動 MySQL 服務

[[email protected] ~]# /etc/init.d/mysqld start
Starting MySQL.Logging to ‘/data/mysql_data/MySQL.err‘.
.. SUCCESS!


* 查看服務是否啟動並監聽端口 [默認3306]

[[email protected] ~]# netstat -lntp | grep 3306
tcp        0      0 :::3306             :::*                LISTEN      20896/mysqld


8. 服務啟動測試

* 通過自帶mysql客戶端連接 [ 使用初始化時輸出的隨機密碼 ]

[[email protected] ~]# /usr/local/mysql/bin/mysql -p‘Z91g%.6d&fay‘
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18

Copyright (c) 2000, 2017, 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>

* 修改密碼

mysql> set password = ‘123456‘;
Query OK, 0 rows affected (0.00 sec)

* 重新使用密碼連接

mysql> quit
Bye
[[email protected] ~]# /usr/local/mysql/bin/mysql -p‘123456‘
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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>



9. 總結


以需求驅動技術,技術本身沒有優略之分,只有業務之分。

本文出自 “sea” 博客,請務必保留此出處http://lisea.blog.51cto.com/5491873/1941607

MySQL5.7--------基於CentOS6二進制包安裝