centos 7 安装 mysql-5.7

实测centos 7 中安装mysql-5.7版本数据库的详细过程,在安装mysql-5.7的时候,可以通过查看日志(/var/log/mysqld.log)提示的错误,进行一步步的调试安装。这样可以快速准确的解决各种问题,完成搭建。

官网下载页面:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

在这里插入图片描述

mysql download section and link.png

一、安装软件

1.下载解压

bash

  #下载软件包
    wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar
    #解压包
    tar -xvf mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar
    #包
    [root@zixuephp ~]# ls
    mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar                 
    mysql-community-libs-5.7.23-1.el7.x86_64.rpm              
    mysql-community-client-5.7.23-1.el7.x86_64.rpm           
    mysql-community-libs-compat-5.7.23-1.el7.x86_64.rpm        
    mysql-community-common-5.7.23-1.el7.x86_64.rpm           
    mysql-community-minimal-debuginfo-5.7.23-1.el7.x86_64.rpm  
    mysql-community-devel-5.7.23-1.el7.x86_64.rpm            
    mysql-community-server-5.7.23-1.el7.x86_64.rpm             
    mysql-community-embedded-5.7.23-1.el7.x86_64.rpm         
    mysql-community-server-minimal-5.7.23-1.el7.x86_64.rpm     
    mysql-community-embedded-compat-5.7.23-1.el7.x86_64.rpm  
    mysql-community-test-5.7.23-1.el7.x86_64.rpm              
    mysql-community-embedded-devel-5.7.23-1.el7.x86_64.rpm
2.依次安装mysql rpm
bash

    rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm --force --nodeps
    rpm -ivh mysql-community-libs-5.7.23-1.el7.x86_64.rpm --force --nodeps
    rpm -ivh mysql-community-client-5.7.23-1.el7.x86_64.rpm --force --nodeps
    rpm -ivh mysql-community-common-5.7.23-1.el7.x86_64.rpm --force --nodeps
    rpm -ivh mysql-community-libs-compat-5.7.23-1.el7.x86_64.rpm --force --nodeps

二、启动mysql

bash

    systemctl start mysqld
    [root@zixuephp ~]# ps -aux|grep mysqld
    mysql    25145  1.5  8.1 1119500 166632 ?      Sl   10:10   0:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

*如果启动失败,则需要对配置文件进行配置(增加配置文件中不存在的下面的配置参数):

bash

    #编辑配置文件
    vim /etc/my.cnf
    #配置文件内容
    #数据库存放目录,如果不存在旧创建
    datadir=/var/lib/mysql/data
    #连接文件,如果不存在则创建,并设置mysql用户所有者和mysql组
    socket=/var/lib/mysql/mysql.sock
    #定义默认时间戳
    explicit_defaults_for_timestamp=true
    #设置运行用户
    user=mysql

三、加入开机启动

bash

systemctl enable mysqld 
systemctl daemon-reload

四、查看默认root密码

bash

cat /var/log/mysqld.log |grep 'temporary password'
[root@localhost]#[Note] A temporary password is generated for root@localhost: iefe_ggtr; #其中 iefe_ggtr; 就是初始密码了。

*如果查询不到密码,需要初始化数据库,生成默认系统库表

bash

mysqld --initialize --user=mysql --console
#运行结果:
[root@localhost /]# mysqld --initialize --user=mysql --console 
[root@localhost /]# grep 'temporary password' /var/log/mysqld.log 
[Note] A temporary password is generated for root@localhost: iefe_ggtr

五、登录mysql

bash

[root@localhost]# 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.23
 
mysql->

六、设置密码

登录后需要对初始密码进行重置操作,否则不能进行下一步的数据库操作

bash

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('e0+fde1/==='); #重置密码,密码不能太简单
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

设置root账号远程可以访问
use mysql;
select user,host from user;
update user set host = ‘%’ where user = ‘root’;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值