一、安装概述
本文将继续配置我的虚拟机,安装mysql服务端,是为了安装hive工具做准备,让mysql作为hive的源数据库,当前mysql版本为社区版5.7.36。
二、安装步骤
- 查看当前linux版本的位数,两种方法
- uname -a ,x86_64显示当前版本为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,直接显示当前位数
[root@hadoop01 ~]# getconf LONG_BIT
64
- mysql下载,两种方法
- 通过界面下载,官网下载地址。本地下载成功后,通过xsecure或xftp工具将其上传到虚拟机上。
https://dev.mysql.com/downloads/mysql/
image.png
image.png
image.png - 通过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
- 创建mysql用户
[root@hadoop01 local]# adduser mysql
- 修改用户权限
[root@hadoop01 local]# chown -R mysql:mysql /usr/local/mysql
- 创建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加入到服务中
[root@hadoop01 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
- 设置开机启动
[root@hadoop01 mysql]# chkconfig mysql on
- 启动mysql服务
[root@hadoop01 mysql]# service mysql start
- 加入环境变量
[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
- 使环境变量生效
[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服务时报错
[root@hadoop01 mysql]# service mysql start
The server quit without updating PID file (/usr/local/mysql/data/hadoop01.pid).
可能是/usr/local/mysql/data/数据目录mysql用户没有权限,解决方案:
- 授予权限
[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
- 重启服务,成功启动
[root@hadoop01 mysql]# service mysql start
网友评论