Centos配置MySQL

Centos7配置MySQL5.7

  1. 查看是否已有数据库配置

    rpm -qa | grep mysql
    # 输出数据库文件名
    
  2. 删除已有的数据库

    rpm -e 输出的文件名
    
  3. 安装wget网络下载工具,已有可跳过

    yum install wget -y
    
  4. 下载MySQL安装包

    wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
    yum -y install mysql57-community-release-el7-10.noarch.rpm
    yum -y install mysql-community-server --nogpgcheck
    

    如果第三条命令运行后出现一下错误。

    ....
    Public key for mysql-community-common-5.7.43-1.el7.x86_64.rpm is not installed
    
    Failing package is: mysql-community-common-5.7.43-1.el7.x86_64
    GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    

    则使用一下命令

    yum -y install mysql-community-server --nogpgcheck
    
  5. 刷新MySQL服务

    systemctl start mysqld.service
    
  6. 查看MySQL运行状态

    service mysqld status
    

    运行状态 active(running)表示运行成功

    [root@hadoop mysql]# service mysqld status
    Redirecting to /bin/systemctl status mysqld.service
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: active (running) since Wed 2023-09-13 07:47:55 CST; 41s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
      Process: 1710 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
      Process: 1660 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
     Main PID: 1713 (mysqld)
       CGroup: /system.slice/mysqld.service
               └─1713 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
    
    Sep 13 07:47:51 hadoop systemd[1]: Starting MySQL Server...
    Sep 13 07:47:55 hadoop systemd[1]: Started MySQL Server.
    
    
  7. 查看初始密码

    [root@hadoop mysql]# grep 'password' /var/log/mysqld.log
    2023-09-12T23:47:52.772803Z 1 [Note] A temporary password is generated for root@localhost: )zpc_k0;NIPi
    # 如上 )zpc_k0;NIPi  表示初始密码
    
  8. 进入MySQL。密码是上面初始密码

    [root@hadoop mysql]# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.7.43
    
    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> 
    
  9. 设置密码。

    ALTER USER USER() IDENTIFIED BY 'root';
    
  10. 如果遇到一下问题。如果没有跳过

    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    

    大意是你的密码太简单,不符合安全策略。解决方案1提升密码难度。2修改安全策略,如下:

    set global validate_password_policy=0
    set global validate_password_length=1;
    
    # validate_password_policy取值
    	# 0 or LOW     只验证长度
    	# 1 or MEDIUM  验证长度、数字、大小写、特殊字符
    	# 2 or STRONG  验证长度、数字、大小写、特殊字符、字典文件
    	
    

    再次设置密码

    mysql> ALTER USER USER() IDENTIFIED BY 'root';
    Query OK, 0 rows affected (0.00 sec)
    
  11. 测试

    # 退出MySQL
    quit
    
    # 重启MySQL服务
    service mysqld start
    
    # 使用新密码登录
    [root@hadoop mysql]# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 5
    Server version: 5.7.43 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> quit
    Bye
    

    完。Centos配置数据库成功。

posted @   凉冰24  阅读(34)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示