一奖唯、安裝概述
本文將繼續(xù)配置我的虛擬機县恕,安裝mysql服務(wù)端东羹,是為了安裝hive工具做準(zhǔn)備,讓mysql作為hive的源數(shù)據(jù)庫忠烛,當(dāng)前mysql版本為社區(qū)版5.7.36属提。
二、安裝步驟
- 查看當(dāng)前l(fā)inux版本的位數(shù),兩種方法
- uname -a 冤议,x86_64顯示當(dāng)前版本為64位
[root@hadoop01 ~]# uname -a
Linux hadoop01 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
- getconf LONG_BIT斟薇,直接顯示當(dāng)前位數(shù)
[root@hadoop01 ~]# getconf LONG_BIT
64
- mysql下載,兩種方法
- 通過界面下載恕酸,官網(wǎng)下載地址堪滨。本地下載成功后,通過xsecure或xftp工具將其上傳到虛擬機上蕊温。
https://dev.mysql.com/downloads/mysql/
- 通過wget命令直接下載到虛擬機
[root@hadoop01 ~]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
- 解壓壓縮包到/usr/local目錄
[root@hadoop01 ~]# tar -xzvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
- 修改mysql文件名稱
[root@hadoop01 ~]# cd /usr/local/
[root@hadoop01 local]# mv mysql-5.7.36-linux-glibc2.12-x86_64/ mysql
- 創(chuàng)建mysql用戶
[root@hadoop01 local]# adduser mysql
- 修改用戶權(quán)限
[root@hadoop01 local]# chown -R mysql:mysql /usr/local/mysql
- 創(chuàng)建data目錄
[root@hadoop01 local]# cd mysql/
[root@hadoop01 mysql]# mkdir data
- 安裝依賴包
[root@hadoop01 mysql]# yum install libaio
- mysql初始化
[root@hadoop01 mysql]# /usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
- 修改配置文件
[root@hadoop01 mysql]# vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
#取消密碼驗證
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
- 將mysql加入到服務(wù)中
[root@hadoop01 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
- 設(shè)置開機啟動
[root@hadoop01 mysql]# chkconfig mysql on
- 啟動mysql服務(wù)
[root@hadoop01 mysql]# service mysql start
- 加入環(huán)境變量
[root@hadoop01 mysql]# vim /etc/profile
export JAVA_HOME=/usr/local/java/jdk1.8.0_311
export PATH=$PATH:$JAVA_HOME/bin:/usr/local/mysql/bin
- 使環(huán)境變量生效
[root@hadoop01 mysql]# source /etc/profile
- 登錄進入mysql袱箱,成功
[root@hadoop01 mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.04 sec)
三、我遇到的問題
- 啟動mysql服務(wù)時報錯
[root@hadoop01 mysql]# service mysql start
The server quit without updating PID file (/usr/local/mysql/data/hadoop01.pid).
可能是/usr/local/mysql/data/數(shù)據(jù)目錄mysql用戶沒有權(quán)限义矛,解決方案:
- 授予權(quán)限
[root@hadoop01 mysql]# chown -R mysql.mysql /urs/local/mysql/
- 殺掉進程
[root@hadoop01 mysql]# ps -ef | grep mysqld
root 29746 1 0 10:30 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/hadoop01.pid
mysql 29961 29746 0 10:30 pts/1 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/usr/local/mysql/data/hadoop01.pid --socket=/tmp/mysql.sock --port=3306
root 30119 29492 0 11:16 pts/0 00:00:00 grep --color=auto mysqld
You have new mail in /var/spool/mail/root
[root@hadoop01 mysql]# kill -9 29746
[root@hadoop01 mysql]# kill -9 29961
- 重啟服務(wù)发笔,成功啟動
[root@hadoop01 mysql]# service mysql start