mysql安装-rpm方式

环境

系统:centos7.9

安装包:mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar(下载:https://dev.mysql.com/downloads/mysql/5.7.html)

安装

  1. 上传安装包到/opt/mysql 并且解压

    # cd /opt/mysql/
    # tar xvf mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar 
    mysql-community-client-5.7.38-1.el7.x86_64.rpm
    mysql-community-common-5.7.38-1.el7.x86_64.rpm
    mysql-community-devel-5.7.38-1.el7.x86_64.rpm
    mysql-community-embedded-5.7.38-1.el7.x86_64.rpm
    mysql-community-embedded-compat-5.7.38-1.el7.x86_64.rpm
    mysql-community-embedded-devel-5.7.38-1.el7.x86_64.rpm
    mysql-community-libs-5.7.38-1.el7.x86_64.rpm
    mysql-community-libs-compat-5.7.38-1.el7.x86_64.rpm
    mysql-community-server-5.7.38-1.el7.x86_64.rpm
    mysql-community-test-5.7.38-1.el7.x86_64.rpm
    
  2. 查看系统中的mariadb包并且卸载

    # rpm -qa | grep mariadb
    # rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
    
  3. 安装依赖

    # yum install -y perl net-tools
    
  4. 安装mysql-community-common

    # rpm -ivh mysql-community-common-5.7.38-1.el7.x86_64.rpm 
    
  5. 安装mysql-community-libs

    # rpm -ivh --force --nodeps mysql-community-libs-5.7.38-1.el7.x86_64.rpm 
    
  6. 安装mysql-community-client

    # rpm -ivh mysql-community-client-5.7.38-1.el7.x86_64.rpm 
    
  7. 安装mysql-community-server

    # rpm -ivh --force --nodeps mysql-community-server-5.7.38-1.el7.x86_64.rpm 
    
  8. 查看mysql客户端是否安装成功

    # which mysql
    /usr/bin/mysql
    
  9. 编辑配置文件

    在[mysqld]段增加一行:skip-grant-tables 跳过本地数据库权限验证 (生产慎用)

    # vim /etc/my.cnf
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    
    [mysqld]
    skip-grant-tables
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    
  10. 启动服务

    # systemctl start mysqld.service
    

设置用户

  1. 进入客户端设置用户

    # mysql
    # 修改root用户密码
    mysql> update mysql.user set authentication_string=password('root') where user='root';
    # 刷新权限
    mysql> flush privileges;
    
  2. 编辑配置文件

    删掉skip-grant-tables 并且重启

    # vim /etc/my.cnf
    skip-grant-tables
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    
    [mysqld]
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    ~                                                               
    
    
    # systemctl restart mysqld.service
    
  3. root用户密码登录

    # mysql -uroot -proot
    
  4. 设置密码的验证强度等级

    set global validate_password_policy=LOW;
    
  5. 设置密码长度

    set global validate_password_length=4;
    
  6. 修改密码

    set password=password('root123456');
    
  7. 开启远程登录权限 mysql不允许用户名密码一致并且拥有远程登录权限 负责报错

    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    grant all privileges on *.* to 'root'@'%' identified by 'root123456' with grant option;
    
  8. 刷新权限

    flush privileges;
    
  9. 退出mysql客户端

    exit
    
posted @   makj  阅读(312)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示