美文网首页
CentOS7.3安装mysql5.7

CentOS7.3安装mysql5.7

作者: 三叉戟渔民 | 来源:发表于2018-08-21 15:23 被阅读0次
    下载

    官网地址

    image.png
    下载后将文件上传到服务器,并赋予755可执行权限

    安装

    1、解压
    [root@localhost soft]# tar -xvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
    
    复制解压后的mysql目录
    [root@localhost soft]# cp -r mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql
    
    2、添加用户组和用户
    添加用户组
    [root@localhost soft]# groupadd mysql
    
    添加用户mysql且添加到用户组mysql
    [root@localhost soft]# useradd -g mysql mysql
    
    3、安装

    安装前需要卸载系统自带的Mysql

    • 检测系统是否安装:
    [root@localhost soft]# rpm -qa | grep mysql
    [root@localhost soft]# rpm -qa | grep mariadb
    
    • 检测到已安装,卸载之:
    [root@localhost soft]# yum -y remove mysql*
    [root@localhost soft]# yum -y remove mariadb*
    
    • 安装
      注:mysql目录下没有data,需要手动创建
      将mysql及其下所有的目录所有者和组均设为mysql
    [root@localhost soft]# cd /usr/local/mysql/
    [root@localhost soft]# chown -R mysql:mysql *
    
    • 初始化
    [root@localhost soft]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
    
    初始化成功信息如下所示:
    2018-08-21T02:51:32.462338Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2018-08-21T02:51:32.970357Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2018-08-21T02:51:33.028257Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2018-08-21T02:51:33.035443Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 1cb0d086-a4ed-11e8-a804-000c29fe8b9d.
    2018-08-21T02:51:33.036418Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2018-08-21T02:51:33.037704Z 1 [Note] A temporary password is generated for root@localhost: 2balpgvBcf!1
    

    注意最后一行,这也是和之有版本不同的地方,它给了root一个初始密码,后面要登录的时候要用到这个密码。

    • 配置
    [root@localhost soft]# vi /etc/my.cnf
    
    [mysqld]
    basedir = /usr/local/mysql
    datadir = /usr/local/mysql/data
    port = 3306
     
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
     
    注意,tmp目录不存在,请自行创建。
    
    4、配置环境变量
    [root@localhost soft]# vi /etc/profile
    export PATH=$PATH:/usr/local/mysql/bin
    
    [root@localhost soft]# source /etc/profile
    
    5、设置mysql以服务运行并且开机启动
    [root@localhost soft]# cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysql
    [root@localhost soft]# chmod +x /etc/init.d/mysql
    
    设置开机启动
    [root@localhost soft]# chkconfig mysql on
    

    启动

    [root@localhost soft]# service mysql start
    

    相关文章

      网友评论

          本文标题:CentOS7.3安装mysql5.7

          本文链接:https://www.haomeiwen.com/subject/vhxjiftx.html