mysql-5.7.24 在centos7安装

搭建环境:mysql5.7.24  CentOS-7-x86_64-DVD-1804.iso  桌面版

1. 进入官网:https://dev.mysql.com/downloads/mysql/

 

该tar包有两个安装文件,如图:

通常我们选择第一个安装,第二个是测试包,另有用途。

2. 上传至centos7

一般搭建环境都是有相应的用户和组,可以自己添加用户和组,我是直接在安装的时候就设置好了centos用户。

tar -zxvf mysql-5.7.24-el7-x86_64.tar.gz -C /指定目录 --用root用户解压

将解压后的mysql文件在root下用chown命令只给你添加的用户--chown 用户名:组名 mysql  ---这般麻烦操作,所以我在安装系统的时候直接在界面设置好了。

3. 在添加的用户下建立mysql数据文件目录:mkdir home/centos/mysql/data   ----~代表当前用户目录

4. 建立软连接:ln -s mysql-5.7.24-el7-x86_64.tar.gz mysql    --便于设置环境变量

5. 添加环境变量:#mysql
export MYSQL_HOME=/soft/mysql
export PATH=$PATH:$MYSQL_HOME/bin

6. mysql初始化--指定安装目录和数据存放目录

./bin/mysqld --initialize --user=用户名 --basedir=安装目录/mysql/data --datadir=/home/centos/mysql/data

在初始化的最下边有一个对root赋权的密码记录下来

7. 复制启动文件并赋予执行权限

cp mysql.server /etc/init.d/mysql_server
chmod +x /etc/init.d/mysql_server

8. 修改mysql_server启动路径(basedir 和datadir 是空的,填上就是)

basedir=安装目录/mysql/data

datadir=/home/centos/mysql/data

9. 刷新配置文件  source  /etc/profile

10. 修改 /etc/my.cnf   --如果不进行初始化,是没有该文件的,这与之前版本是不同的

[client]
port=3306
[mysql_server]
basedir=/soft/mysql
datadir=/home/centos/mysql/data
#socket=/var/lib/mysql/mysql.sock
socket=/tmp/mysql.sock
user=centos
# 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=/soft/mysql/logs/mysql_server.log
pid-file=/soft/mysql/pid/mysql_server.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
开始的时候配置文件不要添加太多的东西,否则不容易成功。
11. 启动mysqld
service mysql_server start 
netstat -anpt   --查看端口

12. 添加开启自启
chkconfig --add mysql_server --添加自启
chkconfig mysql_server on  --开启自启
13. 进入mysql,修改密码 
mysql -u root -p
提示输入密码:前面初始化的密码
set password for 'root'@'localhost'=password('新密码');
授权
grant all on *.* to 用户@'ip' identified by 密码;
flush privileges; 

猜你喜欢

转载自www.cnblogs.com/sdifens/p/10244022.html