关键词搜索

源码搜索 ×
×

Linux centos7 安装 MySQL5.7.x

发布2022-10-28浏览435次

详情内容

一、下载安装

下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

在这里插入图片描述
在这里插入图片描述

下载地址:
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

2. wget 下载方式
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
    3. 安装
    # 解压
    tar -zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
    
    # 再移动并重命名一下
    mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/mysql
    
    # 创建mysql用户组和用户并修改权限
    groupadd mysql
    useradd -r -g mysql mysql
    
    # 创建数据目录并赋予权限
    mkdir -p  /data/mysql              
    chown mysql:mysql -R /data/mysql   
    
    # 配置my.cnf
    vim /etc/my.cnf
    
      2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    内容如下(原内容清空即可):

    [mysqld]
    bind-address=0.0.0.0
    port=3306
    user=mysql
    basedir=/usr/local/mysql
    datadir=/data/mysql
    socket=/tmp/mysql.sock
    log-error=/data/mysql/mysql.err
    pid-file=/data/mysql/mysql.pid
    #character config
    character_set_server=utf8mb4
    symbolic-links=0
    lower_case_table_names=1
    explicit_defaults_for_timestamp=true
    max_connections=1000
    wait_timeout=31536000
    interactive_timeout=31536000
    
      2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    4. 初始化数据库
    # 进入mysql的bin目录
    cd /usr/local/mysql/bin/
    
    # 初始化
    ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
    
    #  查看密码
    cat /data/mysql/mysql.err
    
    # 先将mysql.server放置到/etc/init.d/mysql中
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
    
    # 启动
    service mysql start
    
    # 查看进程
    ps -ef|grep mysql
    
    到这里说明mysql已经安装成功了!!
    
      2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    操作记录:

    [root@localhost app]# tar -zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
    [root@localhost app]# mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/mysql
    [root@localhost app]# groupadd mysql
    [root@localhost app]# useradd -r -g mysql mysql
    [root@localhost app]# mkdir -p  /data/mysql              #创建目录
    [root@localhost app]# chown mysql:mysql -R /data/mysql   #赋予权限
    [root@localhost app]# vim /etc/my.cnf
    [root@localhost app]# cd /usr/local/mysql/bin/
    [root@localhost bin]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
    [root@localhost bin]# cat /data/mysql/mysql.err
    2021-06-23T12:10:13.135921Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2021-06-23T12:10:13.310540Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2021-06-23T12:10:13.354777Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2021-06-23T12:10:13.455013Z 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: f6c9acb5-d41b-11eb-af0b-000c293777d6.
    2021-06-23T12:10:13.457378Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2021-06-23T12:10:14.122833Z 0 [Warning] CA certificate ca.pem is self signed.
    2021-06-23T12:10:14.491356Z 1 [Note] A temporary password is generated for root@localhost: wevML>n_q8=;
    [root@localhost bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
    [root@localhost bin]# service mysql start
    Starting MySQL. SUCCESS! 
    
    [root@localhost bin]# ps -ef|grep mysql
    root       3583      1  0 20:11 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
    mysql      3774   3583  3 20:11 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.err --pid-file=/data/mysql/mysql.pid --socket=/tmp/mysql.sock --port=3306
    root       3806   3157  0 20:12 pts/0    00:00:00 grep --color=auto mysql
    
    
      2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    二、修改密码
    2.1. 修改密码
    # 首先登录mysql
    cd /usr/local/mysql/bin/
    ./mysql -u root -p
    输入密码:(前面的那个是随机生成的)                    
    
      2
    • 3
    • 4
    2.2. 修改密码
    # 再执行下面三步操作,然后重新登录。
    SET PASSWORD = PASSWORD('123456');
    ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
    FLUSH PRIVILEGES;                           
    
      2
    • 3
    • 4

    在这里插入图片描述

    2.3. 允许远程访问

    说明

    # 这时候你如果使用远程连接……你会发现你无法连接。
    use mysql                                            #访问mysql库
    update user set host = '%' where user = 'root';      #使root能再任何host访问
    FLUSH PRIVILEGES;                                    #刷新   
    
      2
    • 3
    • 4

    直接执行

    use mysql;
    update user set host = '%' where user = 'root';
    FLUSH PRIVILEGES;
    
      2
    • 3
    2.4. 关闭防火墙
    systemctl stop firewalld
    

      ok!!!!MySQL5.7就装好了
      在这里插入图片描述

      2.4. 建立mysql软连接

      在这里插入图片描述

      如果不希望每次都到bin目录下使用mysql命令则执行以下命令

      ln -s  /usr/local/mysql/bin/mysql    /usr/bin
      

        在这里插入图片描述

        相关技术文章

        点击QQ咨询
        开通会员
        返回顶部
        ×
        微信扫码支付
        微信扫码支付
        确定支付下载
        请使用微信描二维码支付
        ×

        提示信息

        ×

        选择支付方式

        • 微信支付
        • 支付宝付款
        确定支付下载