【MySQL】MySQL 5.7 初探

楊奇龍發表於2016-05-12
寫在前面
   MySQL 5.7版本於2015年10月份左右 GA,至今已經半年多了,但自己一直沒有時間來follow MySQL 5.7 新的特性,作為MySQL DBA 實在汗顏,以後會花時間來研究5.7 版本的特性並針對部分優化功能做出壓力測試。本文記錄安裝MySQL 5.7 ,(即使參考了官方的文件)整個過程並非之前的版本那麼順利,算是一個嚐鮮,供大家參考。
MySQL  5.7 安裝
本文采用二進位制原始碼包安裝
獲取安裝包
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar
wget http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar
解壓縮
tar -xvf mysql-5.7.12-linux-glibc2.5-x86_64.tar -C /opt/
cd /opt
ls -s mysql-5.7.12-linux-glibc2.5-x86_64 mysql
mkdir -p /srv/my3306/{data,run,tmp,log}

注意 官方提示 
5.7.6版本之前可以使用mysql_install_db 來初始化安裝,但是5.7.6之後的版本已經廢棄了該初始化方式,推薦使用-- initialize 引數完成資料庫初始化的操作。
root@rac4:~# >/opt/mysql/bin/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/srv/my3306/data/
2016-05-10 05:34:13 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-05-10 05:34:14 [ERROR]   Child process: /opt/mysql/bin/mysqldterminated prematurely with errno= 32
2016-05-10 05:34:14 [ERROR]   Failed to execute /opt/mysql/bin/mysqld --bootstrap --datadir=/srv/my3306/data --lc-messages-dir=/opt/mysql/share --lc-messages=en_US --basedir=/opt/mysql
-- server log begin --
2016-05-09T21:34:13.595439Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-05-09T21:34:13.596070Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-05-09T21:34:13.596075Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
-- server log end --
初始化操作


安裝和配置ssl

需要提示各位的是 

MySQL認為在5.7版本之前存在安全問題,存在比較大的隱患,如 MySQL資料庫預設安裝的使用者密碼為空,所有使用者擁有對於MySQL預設安裝test資料庫的訪問許可權 。MySQL 5.7中的root使用者的密碼不再是空,而是在安裝時隨機產生一個密碼,如第一張圖中的紅色註釋.而且官方已經刪除了test資料庫,預設安裝完後是沒有test資料庫的。更為重要的是,MySQL 5.7版本提供了更為簡單SSL安全訪問配置,並且預設連線就採用SSL的加密方式。 關於ssl 的更多知識和效能測試請移步《MySQL的SSL 加密連線與效能開銷
執行完命令mysql_ssl_rsa_setup後會發現datadir 目錄下會多出pem結尾的檔案,而這些檔案就是開啟SSL連線所需要的檔案:


啟動MySQL
root@rac4:/opt/mysql# >bin/mysqld_safe --user=mysql --datadir=/srv/my3306/data  --basedir=/opt/mysql
2016-05-09T22:42:12.101739Z mysqld_safe Logging to '/srv/my3306/data/rac4.err'.
2016-05-09T22:42:12.141157Z mysqld_safe Starting mysqld daemon with databases from /srv/my3306/data

登陸資料庫



小結
  實際上初始化安裝之後 資料庫裡面僅有root@'localhost' 和mysql.sys@'localhost' 兩個使用者,並且第一次需要重置root 密碼。因為這個是第一次安裝,在登陸資料庫的便利性方面沒有做過多研究。但是可以感受到新版本的資料庫在安全性上的考量。
 另外在啟動的時候也遇到了 指定 --defaults-file 識別不了的問題,這個待解決。
  1. root@rac4:/opt/mysql# >./bin/mysqld_safe --user=mysql --defaults-file=/srv/my3306/my.cnf &
  2. [1] 11326
  3. root@rac4:/opt/mysql# >./bin/mysqld_safe: line 541: /usr/local/mysql/data/mysqld_safe.pid: No such file or directory
  4. awk: (FILENAME=- FNR=1) warning: error writing standard output (Broken pipe)
  5. 2016-05-09T22:27:32.088016Z mysqld_safe Logging to '/usr/local/mysql/data/rac4.err'.
  6. touch: cannot touch `/usr/local/mysql/data/rac4.err': No such file or directory
  7. chmod: cannot access `/usr/local/mysql/data/rac4.err': No such file or directory
  8. touch: cannot touch `/usr/local/mysql/data/rac4.err': No such file or directory
  9. chown: cannot access `/usr/local/mysql/data/rac4.err': No such file or directory
  10. 2016-05-09T22:27:32.140094Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
針對這個問題 ,終於解決了,原因在於 官方 mysqld-safe 介紹 

使用 ./bin/mysqld_safe  --defaults-file=/srv/my3306/my.cnf --user=mysql &  即可解決。

5.7 版本的相比於5.6 在安裝過程和使用方式上存在相當大的差異,作為老司機也在坑裡面好久才爬出來。看了本文之後,希望對第一次使用二進位制安裝的朋友有所幫助,路雖崎嶇 (PS 也是我第一次手比較生),但是看官方文件和其他小夥伴對5.7 效能和功能的介紹,還是需要比較深入的探究5.7 版本特性,多讀官方文件,為以後在生產環境落地做預研。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-2098935/,如需轉載,請註明出處,否則將追究法律責任。

相關文章