Linux下安装MySQL5.7.29 详细步骤

Linux下安装MySQL5.7.29 详细步骤

一、下载

进入到mysql官网下载自己对应版本的mysql,
下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
Linux下安装MySQL5.7.29 详细步骤_第1张图片

二、环境配置

  1. 安装前,检查系统是否自带安装了MySQL
[root@wow~]# rpm -qa | grep mysql

如果有,则进行卸载

[root@wow~]# mysql-libs-5.1.52-1.el6_0.1.x86_64   //上述命令返回结果显示已经安装,则进行卸载
[root@wow~]# rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64     //强力删除

centos7默认安装了mariadb,操作同上,检查卸载

  1. 将下载好的MySQL上传到服务器,我放在了usr/local/下,记好自己的路径,后面经常用到

三、安装

  1. 进入到安装包所在路径,解压文件
[root@wow/usr/local]# tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz  
[root@wow/usr/local]# mv mysql-5.7.29-linux-glibc2.12-x86_64 /usr/local/mysql  //为了后面使用方便,将解压后的文件重命名
  1. 添加系统mysql组和mysql用户(新版本默认存在,可跳过)

    检查mysql组和用户是否存在,如无创建

[root@wow/usr/local]# cat /etc/group | grep mysql
#类似   mysql:x:490:  //则说明已存在
[root@wow/usr/local]# cat /etc/passwd | grep mysql
#类似   mysql:x:496:490::/home/mysql:/bin/bash  //则说明已存在

如果没有返回结果,则进行创建

[root@wow~]#groupadd mysql
[root@wow~]#useradd -r -g mysql mysql
#useradd -r参数表示mysql用户是系统用户,不可用于登录系统
  1. 安装数据库
  • 创建data目录
[root@wow~]# cd /usr/local/mysql
[root@wow/usr/local/mysql]# mkdir data
  • 将/usr/local/mysql的所有者及所属组改为mysql
[root@wow/usr/local/mysql]# chown -R mysql.mysql /usr/local/mysql
  • 在/usr/local/mysql/support-files目录下创建my_default.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
 
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
 
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8
 
log-error = /usr/local/mysql/data/mysqld.log
pid-file = /usr/local/mysql/data/mysqld.pid
  • 将该文件拷贝到/etc/my.cnf
[root@wow/usr/local/mysql]# cp support-files/my_default.cnf /etc/my.cnf
  1. 初始化数据库
[root@wow~]# cd /usr/local/mysql
[root@wow/usr/local/mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
  1. 初始化完成之后,查看日志
[root@wow~]# cat /usr/local/mysql/data/mysqld.log

记住初始密码-----记住初始密码-----记住初始密码
就在上面的日志里面

  1. 将启动脚本放到开机初始化目录
[root@wow/usr/local/mysql]# cp support-files/mysql.server /etc/init.d/mysql
  1. 启动mysql 登录mysql
    登录的时候需要用到上面的密码
[root@wow~]# service mysql start
[root@wow~]# cd /usr/local/mysql
[root@wow/usr/local/mysql]# ./bin/mysql -u root -p
  1. 修改密码
mysql> set password=password('lalala');
mysql> grant all privileges on *.* to root@'%' identified by 'lalala';
mysql> flush privileges;
  1. 添加远程访问权限
mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;
  1. 重启MySQL生效
[root@wow~]# service mysql restart

你可能感兴趣的:(Linux下安装MySQL5.7.29 详细步骤)