Centos7.5離線安裝mysql-5.7.26

安裝包下載

https://dev.mysql.com/downloads/mysql/ 
根據系統版本下載 

安裝新版mysql前,需將系統自帶的mariadb-lib卸載

[root@hadoop01 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@hadoop01 ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[root@hadoop01 ~]# rpm -qa|grep mariadb

解壓安裝包

[root@hadoop01 mysql-5.7]# tar -xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-devel-5.7.26-1.el7.x86_64.rpm
mysql-community-libs-5.7.26-1.el7.x86_64.rpm
mysql-community-embedded-5.7.26-1.el7.x86_64.rpm
mysql-community-test-5.7.26-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.26-1.el7.x86_64.rpm
mysql-community-common-5.7.26-1.el7.x86_64.rpm
mysql-community-devel-5.7.26-1.el7.x86_64.rpm
mysql-community-client-5.7.26-1.el7.x86_64.rpm
mysql-community-server-5.7.26-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm

安裝mysql-community-common-5.7.26-1.el7.x86_64.rpm

[root@hadoop01 mysql-5.7]# rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.26-1.e################################# [100%]

安裝mysql-community-libs-5.7.26-1.el7.x86_64.rpm

[root@hadoop01 mysql-5.7]# rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.26-1.el7################################# [100%]

安裝mysql-community-client-5.7.26-1.el7.x86_64.rpm

[root@hadoop01 mysql-5.7]# rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.26-1.e################################# [100%]

安裝mysql-community-server-5.7.20-1.el7.x86_64.rpm

在安裝之前需要安裝libaio

[root@hadoop01 mysql-5.7]# rpm -qa|grep libaio
libaio-0.3.109-13.el7.x86_64

如果不存需要下載離線包: 
http://mirror.centos.org/centos/6/os/x86_64/Packages/ 

安裝libaio庫:

rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm(若在有網情況下可執行yum install libaio)

安裝server,rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm

[root@hadoop01 mysql-5.7]# rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.26-1.e################################# [100%]

初始化數據庫

// 指定datadir, 執行後會生成~/.mysql_secret密碼文件(5.7以後不在使用)
[root@hadoop01 mysql-5.7]# mysql_install_db --datadir=/var/lib/mysql

// 初始化,執行生會在/var/log/mysqld.log生成隨機密碼
[root@hadoop01 mysql-5.7]# mysqld --initialize

更改mysql數據庫目錄的所屬用戶及其所屬組(沒用創建mysql用戶)

[root@hadoop01 mysql-5.7]# chown mysql:mysql /var/lib/mysql -R

啓動mysql

[root@hadoop01 mysql-5.7]# systemctl start mysqld.service

授權

[root@hadoop01 mysql-5.7]# chmod -R 777 mysql

查看效果

[root@hadoop01 mysql-5.7]# systemctl status mysqld.service

 

登錄到mysql,更改root用戶的密碼 

命令可以查看初始密碼

grep 'temporary password' /var/log/mysqld.log

[root@hadoop01 mysql-5.7]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 MySQL Community Server (GPL)

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

# 修改root用戶的密碼
mysql> set password=password('你要修改的密碼');
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

# 刷新該表
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

# 退出MySQL
mysql> quit;
Bye

 遠程登陸授權

[root@hadoop01 mysql-5.7]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 MySQL Community Server (GPL)

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

# root用戶遠程登錄
mysql> grant all privileges on *.* to 'root'@'%' identified by '你的密碼' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

# 刷新表
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

# 退出MySQL
mysql> quit;
Bye

設置mysql開機啓動 

// 檢查是否已經是開機啓動
[root@hadoop01 mysql-5.7]# systemctl list-unit-files | grep mysqld

// 開機啓動
[root@hadoop01 mysql-5.7]# systemctl enable mysqld.service

默認配置文件路徑:

配置文件:/etc/my.cnf 
日誌文件:/var/log/mysqld.log 
服務啓動腳本:/usr/lib/systemd/system/mysqld.service 
socket文件:/var/run/mysqld/mysqld.pid

配置默認編碼爲utf8

修改/etc/my.cnf配置文件,在[mysqld]下添加編碼配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

 

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