环境
Linux Centos7 虚拟机
版本:CentOS Linux release 7.9.2009 (Core)
安装准备
官网下载
下载地址
MySQL :: Download MySQL Community Server (Archived Versions)
一定要选Linux-Generic 这是通用版本,这里我选的是64位版本。
下载到windows宿主机后,通过XFTP与XShell导入到虚拟机内。
mysql-5.7.20-linux-glibc2.12-x86_64.tar
安装步骤
一、新建文件目录
在/usr/local/ 目录下新建文件夹
mkdir /usr/local/mysql
mkdir /usr/local/mysql/data
mkdir /usr/local/mysql/log
mkdir /usr/local/mysql/run
二、解压tar包
tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar
解压后将解压文件夹里的内容全部移动到/usr/local/mysql目录下。
三、新建用户与用户组
groupadd mysql
useradd mysql -g mysql
四、文件夹改变属组
chown -R mysql:mysql /usr/local/mysql
五、修改配置文件
因为安装方式为解压缩,因此,/etc/目录下没有my.cnf文件,需要自己vim建立一个。
配置文件如下:
[mysqld]
#skip-grant-tables
#跳过登陆密码
#mysql服务端口
port=3306
server_id=1
# 安装目录
basedir=/usr/local/mysql
#数据存放目录
datadir=/usr/local/mysql/data
#sock文件地址
socket=/tmp/mysql.sock
#错误日志存放地址
log-error=/usr/local/mysql/log/mysql.log
#pid文件地址
pid-file=/usr/local/mysql/data/mysql.pid
#服务端编码
character-set-server=utf8
# lower_case_table_name=1
六、设置开机启动
[root@localhost mysql] cp ./support-files/mysql.server /etc/init.d/mysqld
七、启动mysql
首次启动先进行初始化,进入到 /usr/local/mysql/ 目录下,执行:
[root@bogon mysql] ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
初始化将初始生成初始化密码,密码位置在 /usr/local/mysql/log/mysq.log文件中,这是先前写在/etc/my.cnf文件中的路径。
八、登陆mysql
启动并登陆mysql:
[root@bogon log] service mysqld start
Starting MySQL. SUCCESS!
登陆mysql,密码为mysql.log中的密码。
[root@bogon log] mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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.
mysql>
亲测登陆成功 !