Centos7.2離線安裝mysql5.7.20
阿新 • • 發佈:2018-12-30
安裝包下載
安裝新版mysql前,需將系統自帶的mariadb-lib解除安裝
[root@hadoop ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@hadoop ~]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
[root@hadoop ~]# rpm -qa|grep mariadb
解壓安裝包
tar -xvf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
安裝
mysql-community-common-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
mysql-community-libs-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm
mysql-community-client-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
mysql-community-server-5.7.20-1.el7.x86_64.rpm
在安裝之前需要安裝libaio
[root@hadoop app]# rpm -qa|grep libaio
libaio-0.3.109-13.el7.x86_64
安裝libaio庫:
rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm(若在有網情況下可執行yum install libaio)
安裝server
rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
初始化資料庫
// 指定datadir, 執行後會生成~/.mysql_secret密碼檔案(5.7以後不在使用)
[root@slave mytmp]# mysql_install_db --datadir=/var/lib/mysql
// 初始化,執行生會在/var/log/mysqld.log生成隨機密碼
[root@slave mytmp]# mysqld --initialize
更改mysql資料庫目錄的所屬使用者及其所屬組(沒用建立mysql使用者)
chown mysql:mysql /var/lib/mysql -R
啟動mysql
systemctl start mysqld.service
問題分析
Process: 5924 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=1/FAILURE)
跟蹤日誌/var/log/mysqld.log
授權
chmod -R 777 mysql
檢視效果
登入到mysql,更改root使用者的密碼
命令可以檢視初始密碼
grep 'temporary password' /var/log/mysqld.log
set password=password('123456a?');
建立使用者,及作許可權分配
CREATE USER 'sunld'@'%' IDENTIFIED BY '123456a?';
GRANT ALL PRIVILEGES ON *.* TO 'sunld'@'%';
flush privileges;
遠端登陸授權
grant all privileges on *.* to 'root'@'%' identified by '123456a?' with grant option;
flush privileges;
設定mysql開機啟動
// 檢查是否已經是開機啟動
systemctl list-unit-files | grep mysqld
// 開機啟動
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'