天天看點

CentOS 7 MySql 解壓版安裝配置

CentOS 7 MySql 解壓版安裝配置

下載下傳

通路www.mysql.com

點選DOWNLOADS-->Community-->MySQL Community Server

選擇要下載下傳的版本,目前可選擇的有:5.5、5.6、5.7、8.0,這裡以5.7為例,是以選擇的是5.7。

作業系統選擇Red Hat Enterprise Linux / Oracle Linux,作業系統版本選擇Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit),下面清單過濾的找到Compressed TAR Archivetar壓縮檔案下載下傳即可,這裡選擇的是mysql-5.7.25-el7-x86_64.tar.gz。

将檔案下載下傳到CentOS伺服器上,或者通過Windows下載下傳後上傳到CentOS伺服器上。

(這裡将檔案放到/opt/soft/mysql-5.7.25-el7-x86_64.tar.gz)

安裝配置

1、添加組和使用者

2、解壓到指定位置

這裡準備将mysql放到/opt/program/mysql目錄中。

建立/opt/program/目錄。

進入到/opt/program/目錄。

解壓/opt/soft/mysql-5.7.25-el7-x86_64.tar.gz檔案,不指定目錄的話,會解壓到使用者所在的目錄(也就是/opt/program/)。

重新命名檔案夾名為mysql。

建立資料庫目錄data。

mysql-5.7.25-el7-x86_64/bin/myisam_ftdump

mysql-5.7.25-el7-x86_64/bin/myisamchk

mysql-5.7.25-el7-x86_64/bin/myisamlog

mysql-5.7.25-el7-x86_64/bin/myisampack

mysql-5.7.25-el7-x86_64/bin/mysql

…………

3、給使用者群組賦權

4、初始化mysql資料庫

初始化需要指定mysql程式的目錄以及資料庫的目錄

2019-03-16T14:28:52.317678Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2019-03-16T14:28:54.382317Z 0 [Warning] InnoDB: New log files created, LSN=45790

2019-03-16T14:28:54.699000Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2019-03-16T14:28:54.772198Z 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: d3d169f0-47f7-11e9-9ce7-000c291627c9.

2019-03-16T14:28:54.773910Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2019-03-16T14:28:54.775717Z 1 [Note] A temporary password is generated for root@localhost: hxwVZi*0-e3<

警告可以先不管,最後的位置是随機生成的root密碼hxwVZi*0-e3<

5、配置my.cnf檔案

mysql啟動時,預設會查找/etc/my.cnf檔案作為配置檔案。

配置示例如下:

[mysql]

default-character-set=utf8

[mysqld]

lower_case_table_names=1

basedir=/opt/program/mysql

datadir=/opt/program/mysql/data

port=3306

character-set-server=utf8

max_connections=2000

innodb_buffer_pool_size=128M

log-error=/opt/program/mysql/data/error.log

pid-file=/opt/program/mysql/data/mysql.pid

socket=/opt/program/mysql/mysql.sock

6、為mysql配置環境變量

可以通過/etc/profile檔案配置。

打開該檔案,在最末尾的位置加上

PATH=$PATH:/opt/program/mysql/bin

儲存退出,再執行

通過# echo $PATH可以檢視環境變量資訊

7、制作自啟動服務

第一種,将mysql.server複制到/etc/ini.d/目錄下配置自啟動服務

通過# chkconfig --list檢視是否添加成功

然後通過service指令控制

第二種,通過systemd制作自啟動服務

[Unit]

Description=mysql service

[Service]

Type=forking

ExecStart=/opt/program/mysql/support-files/mysql.server start

ExecStop=/opt/program/mysql/support-files/mysql.server stop

User=mysql

[Install]

WantedBy=multi-user.target

然後通過systemctl指令控制即可,啟動服務和啟用自啟動

第三種,通過systemd制作自啟動服務,并且通過mysql/bin/mysqld來啟動,my.cnf可以自定義位置。(參照于Windows服務的啟動配置) mysql.service配置示例如下:

ExecStart=/opt/program/mysql/bin/mysqld --defaults-file=/opt/program/mysql/my.cnf --user=mysql

錯誤:error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

解決方法: 檢查是否有libaio庫# rpm -qa|grep libaio,如果沒有則安裝# yum install libaio。

原文連接配接:

https://www.junio.cn https://www.cnblogs.com/junio