目录
1、去官网下载mysql安装包(下面是下载链接,可自行下载)
1、去官网下载mysql安装包(下面是下载链接,可自行下载)
https://www.mysql.com/downloads/https://downloads.mysql.com/archives/community/https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz2、通过xftp将tar包上传到Linux环境下
3、解压安装包,将安装包放到指定目录(这里放到opt下)
tar -zxvf /opt/mysql-5.7.43-el7-x86_64.tar.gz -C /opt
目录替换为自己的目录
4、安装
# 添加mysql组 groupadd mysql # 创建用户mysql并将友好加到组mysql useradd -g mysql mysql# 进入mysql目录下、创建data文件夹
cd /opt/mysql-5.7.43-el7-x86_64/
mkdir data
# 初始化数据库:指定用户、指定安装目录、指定数据目录
./bin/mysqld --initialize --user=mysql --basedir=/opt/mysql-5.7.43-el7-x86_64 --datadir=/opt/mysql-5.7.43-el7-x86_64/data
注:执行尾部 “0i8!JKQg2Tne”是初始化密码,密码是随机产生的,每次都不一样。
# 给MySQL文件目录授权 -R是渗透授权
chmod -R 777 /opt/mysql-5.7.43-el7-x86_64
4、制作MySQL启动文件
# 拷贝启动文件,并改名为mysqld cp support-files/mysql.server /etc/init.d/mysqld # 设置启动文件的权限 chmod 777 /etc/init.d/mysqld # 拷贝文件 cp bin/my_print_defaults /usr/bin/5、修改启动脚本
先修改”/etc/init.d/mysqld“
vim /etc/init.d/mysqld
# vi /etc/init.d/mysqld # 配置MySQL的主目录 basedir=/opt/mysql-5.7.43-el7-x86_64# 配置MySQL的数据目录 datadir=/opt/mysql-5.7.43-el7-x86_64/data# 配置MySQL的端口 port=3306 然后配置”/etc/my.cnf“vim /etc/my.cnf[mysqld]
datadir=/opt/mysql-5.7.43-el7-x86_64/data
basedir=/opt/mysql-5.7.43-el7-x86_64
socket=/opt/mysql-5.7.43-el7-x86_64/mysql.sock
user=mysql
tmpdir=/tmp
# 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=/opt/mysql-5.7.43-el7-x86_64/data/error.log
pid-file=/opt/mysql-5.7.43-el7-x86_64/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
6、配置环境变量
配置环境变量文件 “/etc/profile”
export MYSQL_HOME=/opt/mysql-5.7.43-el7-x86_64
export PATH=$PATH:$MYSQL_HOME/bin
生效环境变量
source /etc/profile
7、启动MySQL服务
service mysqld start
8、登录mysql进行配置
密码输入上面初始化生成的初始化密码:“0i8!JKQg2Tne”
# 修改密码:注意密码不能太容易。 set password for root@localhost=password('123456'); # 设置MySQL远程可以登录。 use mysql; update user set host = '%' where user ='root'; flush privileges;