Linux 安裝MySQL 8.0.12之 RPM 安裝體驗
MySQL 8.0.12 版本於2018.07.27日釋出,距離上一個版本MySQL8.0.11版本(2018.04.19)相距三個月多,其中新版本加入了一些新的功能,尤其是instand add column功能蠻令人期待的。
1.Instant Add Column。由騰訊遊戲團隊貢獻程式碼,MariaDB 自10.3.2版本已經支援該功能。
2.BLOB小批量更新優化,這裡的小批量更新是修改的資料大小為100bytes。
核心思想是撤銷(undo)BLOB的更新向量,從而避免將前後映象寫入到表空間,從而節省時間和空間。
經過sysbench壓力測試,更新JSON文件的單個整數 QPS的效能提高2到3倍。
3.MTS的引數 slave_pending_jobs_size_max預設值由16M增加到128M,增加MTS的event applier的buffer。
4.Group Replication增加對GCX/Xcom的記憶體使用的監控,可以在performance_schema中檢視。
5.Query Rewrite Plugin:增加了對insert、update、delete操作的支援,之前此外掛僅支援select語句。
6.windows functions: 新增視窗聚合函式BIT_AND, BIT_OR and BIT_XOR 。
7.GIS新增函式ST_Latitude() and ST_Longitude()來獲取經緯度。
隨著MySQL8.0.12版本的釋出下列MySQL的產品線也更新到8.0.12版本:
MySQL workbench
MySQL Shell
MySQL router
MySQL on Windows (Installer & Tools)
一系列驅動程式的更新:
mysql-connector-odbc mysql-connector-java mysql-connector-net mysql-connector-nodejs mysql-connector-python 支援Python2.7 3.5 和3.6版本 MySQL Connector/C MySQL Connector/C++
國內可以通過映象網站快速下載:(不過國內的網站只能映象2個最新的小版本,下載歷史版本還要要到mysql官方下載的)
官方下載地址:
檢視作業系統: # cat /etc/centos-release CentOS Linux release 7.5.1804 (Core) --解壓檔案: tar -xvf mysql-8.0.12-1.el7.x86_64.rpm-bundle.tar 可以看到解壓後的檔案有10個RPM包: mysql-community-client-8.0.12-1.el7.x86_64.rpm mysql-community-common-8.0.12-1.el7.x86_64.rpm mysql-community-devel-8.0.12-1.el7.x86_64.rpm mysql-community-embedded-compat-8.0.12-1.el7.x86_64.rpm mysql-community-libs-8.0.12-1.el7.x86_64.rpm mysql-community-libs-compat-8.0.12-1.el7.x86_64.rpm mysql-community-minimal-debuginfo-8.0.12-1.el7.x86_64.rpm mysql-community-server-8.0.12-1.el7.x86_64.rpm mysql-community-server-minimal-8.0.12-1.el7.x86_64.rpm mysql-community-test-8.0.12-1.el7.x86_64.rpm 我們只需要依次安裝需要的幾個RPM包即可,安裝之前需要解除安裝掉centos自帶的mariadb-libs: rpm -e --nodeps mariadb-libs rpm -ivh mysql-community-common-8.0.12-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-8.0.12-1.el7.x86_64.rpm rpm -ivh mysql-community-client-8.0.12-1.el7.x86_64.rpm rpm -ivh mysql-community-server-8.0.12-1.el7.x86_64.rpm #systemctl start mysqld #systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2018-07-28 22:55:26 CST; 41min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 3834 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 3902 (mysqld) Status: "SERVER_OPERATING" CGroup: /system.slice/mysqld.service └─3902 /usr/sbin/mysqld Jul 28 22:55:22 node4.example.com systemd[1]: Starting MySQL Server... Jul 28 22:55:26 node4.example.com systemd[1]: Started MySQL Server. # systemctl enable mysqld # systemctl list-unit-files | grep -i mysql mysqld.service enabled [email protected] disabled --登入MySQL: 由於RPM預設安裝會找my.cnf去生產錯誤日誌檔案和資料檔案,在MySQL5.7之後使用安全的安裝方式會隨機生產一個臨時密碼存放在錯誤日誌檔案中。 # cat /etc/my.cnf | grep -v ^# [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid # cat /var/log/mysqld.log | grep -i temporary 2018-07-28T14:55:23.475303Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Tt8S./Tc;HuB 輸入隨機產生的密碼: # mysql -p -S /var/lib/mysql/mysql.sock Enter password: 登入之後需要修改密碼並建立一個可以遠端登入的使用者: mysql> alter user root@'localhost' identified by 'oracle'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements mysql> alter user root@'localhost' identified by 'oracle@2018'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements mysql> alter user root@'localhost' identified by 'Oracle@2018'; Query OK, 0 rows affected (0.11 sec) mysql> show variables like '%valid%'; +--------------------------------------+--------+ | Variable_name | Value | +--------------------------------------+--------+ | validate_password.check_user_name | ON | | validate_password.dictionary_file | | | validate_password.length | 8 | | validate_password.mixed_case_count | 1 | | validate_password.number_count | 1 | | validate_password.policy | MEDIUM | | validate_password.special_char_count | 1 | +--------------------------------------+--------+ 7 rows in set (0.00 sec) 可以看到自MySQL5.7一來的RPM安裝後的密碼強度至少一個大寫字母+一個數字+一個特殊符號。 使用傳統語句建立遠端登入的使用者,可以看到MySQL8.0版本開始不支援傳統的建立使用者和授權寫到一起的方法,需要將建立使用者和授權分開: mysql> grant all privileges on *.* to root@'%' identified by 'Oracle@2018' with grant option; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'Oracle@2018' with grant option' at line 1 mysql> create user root@'%' identified by 'Oracle@2018'; Query OK, 0 rows affected (0.07 sec) mysql> grant all privileges on *.* to root@'%' with grant option; Query OK, 0 rows affected (0.06 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 檢視錯誤日誌的資訊時候會發現時區和北京時間的時區不一致,相差八個小時,不太習慣於平常的日誌檢視: mysql> select now(); +---------------------+ | now() | +---------------------+ | 2018-07-28 23:07:03 | +---------------------+ 1 row in set (0.00 sec) mysql> system cat /var/log/mysqld.log 2018-07-28T14:55:22.384191Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.12) initializing of server in progress as process 3855 2018-07-28T14:55:23.475303Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Tt8S./Tc;HuB 2018-07-28T14:55:24.124940Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.12) initializing of server has completed 2018-07-28T14:55:26.149309Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.12) starting as process 3902 2018-07-28T14:55:26.440808Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2018-07-28T14:55:26.458527Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.12' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL. mysql> 此時需要引數為: mysql> set global log_timestamps=system; Query OK, 0 rows affected (0.00 sec) 不過若要重啟MySQL生效的話還需要寫到配置檔案my.cnf: 若使用SQLyog等客戶端登入MySQL會報錯(MySQL workbench 8.0.12則不會報錯): error 2059: Authentication plugin 'caching_sha2_password' cannot be loaded 解決辦法為修改認證外掛: mysql> select host,user,authentication_string ,plugin from mysql.user where user='root'; +-----------+------+------------------------------------------------------------------------+-----------------------+ | host | user | authentication_string | plugin | +-----------+------+------------------------------------------------------------------------+-----------------------+ | % | root | $A$005$z`}{.J~ht)Dv2M%o.i&2ZxkUAe8TuCngYYWT5qjGl8zPL1.1C3/f68wFeLycFB | caching_sha2_password | | localhost | root | $A$005$?yI;3Ws_ U!2lYXRno46hSXNTL9Hz7t.apqvDebR5kGvPprMDvH27z1 | caching_sha2_password | +-----------+------+------------------------------------------------------------------------+-----------------------+ 2 rows in set (0.00 sec) mysql> alter user root@'%' identified WITH mysql_native_password by 'Oracle@2018'; Query OK, 0 rows affected (0.07 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> select host,user,authentication_string ,plugin from mysql.user where user='root'; +-----------+------+------------------------------------------------------------------------+-----------------------+ | host | user | authentication_string | plugin | +-----------+------+------------------------------------------------------------------------+-----------------------+ | % | root | *FFB4B151EBAD3082A29A4BED121A7F09718E934D | mysql_native_password | | localhost | root | $A$005$?yI;3Ws_ U!2lYXRno46hSXNTL9Hz7t.apqvDebR5kGvPprMDvH27z1 | caching_sha2_password | +-----------+------+------------------------------------------------------------------------+-----------------------+ 2 rows in set (0.00 sec) 若需要後續的新建立的使用者預設使用mysql_native_password 還需要寫入到引數檔案。 由於Linux系統預設是區分大小寫的,在MYSQL中也是區分,為了便於平時的開發和書寫需要修改引數以支援不區分大小寫。 所以my.cnf檔案中至少需要加上如下配置,然後重啟MySQL: [mysqld] log_timestamps = SYSTEM lower_case_table_names = 1 default-authentication-plugin =mysql_native_password 此時還會報錯: [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0'). 若要不區分大小寫則在啟動mysql之前將lower_case_table_names = 1寫入到配置檔案或者 需要刪除datadir目錄下的所有檔案重新啟動初始化資料檔案。 若要在8.0版本中關閉密碼強度驗證只需要解除安裝元件即可: mysql> UNINSTALL COMPONENT 'file://component_validate_password'; Query OK, 0 rows affected (0.01 sec) mysql> show variables like 'valid%pass%'; Empty set (0.00 sec) 而在MySQL5.6 和5.7版本中則需要在my.cnf檔案中寫入: validate_password=OFF 若不想使用RPM安裝後的MySQL則可以解除安裝: # rpm -qa | grep -i mysql mysql-community-common-8.0.12-1.el7.x86_64 mysql-community-client-8.0.12-1.el7.x86_64 mysql-community-libs-8.0.12-1.el7.x86_64 mysql-community-server-8.0.12-1.el7.x86_64 # rpm -e --nodeps `rpm -qa | grep -i mysql` 解除安裝之後刪除資料目錄檔案和日誌檔案即可: # rm -rf /var/lib/mysql/* # rm -rf /var/log/mysqld.log
參考: