离线安装Mysql8 Centos7

  • 到mysql官网(https://dev.mysql.com/downloads/mysql/)下载 linux 版本
  • 查看系统中是否存的mariadb
    > rpm -qa | grep mariadb
    rpm -e --nodeps mariadb-xxxxx.x86_64
  • 解压mysql并且移动
    > mv mysql-xxxx /opt/mysql8.0
  • 创建mysql用户和组:
    > groupadd mysql
    useradd -g mysql mysql
    passwd mysql
  • 创建数据库的数据目录、日志目录和临时目录
    > mkdir /opt/mysql8.0/data
    mkdir /opt/mysql8.0/log
    mkdir /opt/mysql8.0/tmp
  • 将mysql目录及子目录的所属用户及组都设置为mysql
    > chown -R mysql:mysql /opt/mysql8.0
  • 在etc目录下创建my.cnf配置文件
    > [client]
    port = 3306
    socket = /opt/mysql8.0/tmp/mysql.sock
    [mysqld]
    port = 3306
    basedir = /opt/mysql8.0
    datadir = /opt/mysql8.0/data
    tmpdir = /opt/mysql8.0/tmp
    socket = /opt/mysql8.0/tmp/mysql.sock
    pid-file = /opt/mysql8.0/log/mysql.pid
    log_error = /opt/mysql8.0/log/error.log
    slow_query_log_file = /opt/mysql8.0/log/slow.log
  • 初始化数据库
    > /opt/mysql8.0/bin/mysqld --initialize --user=mysql
  • 设置开机自启动mysql服务
    > cp /opt/mysql8.0/support-files/mysql.server /etc/rc.d/init.d/mysqld
    chmod +x /etc/rc.d/init.d/mysqld
    chkconfig --add mysqld
  • 切换mysql用户并且启动mysql
    > su mysql
    service mysqld start
  • 获取初始密码
    > log/error.log里
  • mysql -u root -p 登录修改密码
    > use mysql
    select host, user, authentication_string, plugin from user;
    alter user 'root'@'localhost'IDENTIFIED BY 'newpassword';
    ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root@123';
  • 忘记秘密,重置
    skip-grant-tables
    1) use mysql;
    2) update user set authentication_string='' where user='root';// 如果这个字段有值,先置为空,之前的版本密码字段是password
    3) flush privileges;// 刷新权限表
    4) 执行select user,host from user;// 查看用户及host,方便后续修改
    5) ALTER user 'root'@'%' IDENTIFIED BY 'root@123';// 修改root 密码
    6) exit;//退出mysql

发表评论

电子邮件地址不会被公开。