Linux安装mysql8

Linux安装mysql8

  • 第一步:解压mysql安装包:tar -xvf mysql-server-8.0.25.tar.gz

  • 第二步:更新文件夹名:mv mysql-server-8.0.25 mysql

  • 第三步:进入mysql文件夹:cd mysql,创建data文件夹:mkdir data

  • 第四步:创建mysql用户组和mysql用户:

    groupadd mysql
    
    useradd -g mysql mysql
    
  • 第五步:改变mysql目录权限:chown -R mysql.mysql /opt/soft/mysql/

  • 第六步:配置my.cnf,进入etc文件夹,替换my.cnf文件

    [mysqld]
    bind-address=0.0.0.0
    port=3306
    user=mysql
    basedir=/opt/soft/mysql
    datadir=/opt/soft/mysql/data
    socket=/opt/soft/mysql/data/mysql.sock
    # 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
    [client]
    port=3306
    socket=/opt/soft/mysql/data/mysql.sock
    
    [mysqld_safe]
    
    #
    # include all files from the config directory
    #
    !includedir /etc/my.cnf.d
    
  • 第七步:进入bin文件夹:cd /opt/soft/mysql/bin

    初始化数据库:./mysqld --defaults-file=/etc/my.cnf --basedir=/opt/soft/mysql/ --datadir=/opt/soft/mysql/data/ --user=mysql –initialize

  • 第八步:记录初始化生成的密码

    Linux安装mysql8_第1张图片

  • 第九步:将mysql放在本地系统服务中:

    cp /opt/soft/mysql/support-files/mysql.server /etc/init.d/mysql

  • 第十步:添加到系统服务器:chkconfig --add mysql,查看是否添加成功:chkconfig --list mysql

    Linux安装mysql8_第2张图片

  • 第十一步:启动mysql:service mysql start,如果失败,切换mysql用户:su mysql

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tcTwXPY0-1686644594198)(C:\Users\zhangwei\AppData\Roaming\Typora\typora-user-images\image-20230613162108967.png)]

  • 第十二步:进入bin目录:cd /opt/soft/mysql/bin,登录mysql:进入mysql的bin目录下,登录mysql:./mysql -u root –p,密码为第九步记录的初始密码

    Linux安装mysql8_第3张图片

  • 第十三步:更改密码:ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

  • 第十四步:刷新权限:flush privileges;

  • 第十五步:开放远程连接:

     use mysql
    
     select host,user from user;
    
     update user set host='%' where user='root';
    
     flush privileges;
    

    Linux安装mysql8_第4张图片

  • 第十六步:使用navicat远程连接测试

你可能感兴趣的:(linux,mysql,数据库)