CentOS7安装mysql

安装Mysql

  1. 切换阿里云镜像服务

    [root@cdh1 ~]# yum -y install wget
    
    ## 备份CentOS-Base.repo
    [root@cdh1 ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
    
    [root@cdh1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    
    [root@cdh1 ~]# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
    
    [root@cdh1 ~]# yum clean all
    
    [root@cdh1 ~]# yum makecache
    
  2. 下载mysql的yum源

    [root@cdh1 ~]# wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
    
  3. 安装yum repo源

    [root@cdh1 ~]# rpm -ivh mysql57-community-release-el7-7.noarch.rpm
    
  4. 查看mysql yum repo是否安装成功

    [root@cdh1 ~]# ls /etc/yum.repos.d/
    CentOS-Base.repo      CentOS-Debuginfo.repo  CentOS-Sources.repo        epel-7.repo
    CentOS-Base.repo.bak  CentOS-fasttrack.repo  CentOS-Vault.repo          mysql-community.repo
    CentOS-CR.repo        CentOS-Media.repo      CentOS-x86_64-kernel.repo  mysql-community-source.repo
    
  5. 执行安装mysql

    [root@cdh1 ~]#  yum install mysql-server
    
    [root@cdh1 ~]# yum install mysql-devel
    
    [root@cdh1 ~]# yum install mysql
    
    • 若安装过程中,出现这个错误

      warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-devel-5.7.41-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
      Public key for mysql-community-devel-5.7.41-1.el7.x86_64.rpm is not installed
      mysql-community-devel-5.7.41-1.el7.x86_64.rpm                                                            | 4.2 MB  00:01:23     
      Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
      
      
      The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package.
      Check that the correct key URLs are configured for this repository.
      
      
       Failing package is: mysql-community-common-5.7.41-1.el7.x86_64
       GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
      

      需要把MySQL的GPG更新到最新后,再执行上述安装命令

      [root@cdh1 ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
      
  6. 设置开机自动启动mysql

    [root@cdh1 ~]# systemctl enable mysqld.service
    
  7. 启动mysql

    [root@cdh1 ~]# systemctl start mysqld.service
    
  8. 开启用户远程链接权限

    刚安装,不知道密码,先取消权限认证(生产不要这么玩)

    在/etc/my.cnf文件中最后添加一行:
    
    skip-grant-tables
    

    重启Mysql

    [root@cdh1 ~]# systemctl restart mysqld
    

    进入Mysql,执行以下操作

    [root@cdh1 ~]# mysql -uroot -p
    ## 回车即可
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.7.41 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2023, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    ## 切换到mysql数据库
    mysql> use mysql;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    ## 删除所有用户
    mysql> delete from user;
    Query OK, 3 rows affected (0.00 sec)
    
    ## 配置root用户使用密码123456从任何主机都可以连接到mysql服务器
    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    ## 刷新权限
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> 
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值