运维笔记之centos7安装mysql数据库

安装wget

[root@stem-mysql ~]# yum install wget -y


...
总下载量:547 k
安装大小:2.0 M
Downloading packages:
wget-1.14-18.el7_6.1.x86_64.rpm                                                                                                                                  | 547 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : wget-1.14-18.el7_6.1.x86_64                                                                                                                                         1/1 
  验证中      : wget-1.14-18.el7_6.1.x86_64                                                                                                                                         1/1 

已安装:
  wget.x86_64 0:1.14-18.el7_6.1 

下载官方rpm包

[root@stem-mysql ~]# cd /tmp/
[root@stem-mysql tmp]# wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

...
2023-12-14 07:52:47 (231 MB/s) - 已保存 “mysql57-community-release-el7-8.noarch.rpm” [9116/9116])

安装依赖包

[root@stem-mysql tmp]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm 
警告:mysql57-community-release-el7-8.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql57-community-release-el7-8  ################################# [100%]

导入官方公钥

如果使用的4.1以上版本的rpm的话,除了import mysql的公钥到个人用户的配置中,还需要import mysql的公钥到RPM的配置中

[root@stem-mysql tmp]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

安装数据库服务

[root@stem-mysql tmp]# yum -y install mysql-community-server

...
已安装:
  mysql-community-libs.x86_64 0:5.7.44-1.el7                mysql-community-libs-compat.x86_64 0:5.7.44-1.el7                mysql-community-server.x86_64 0:5.7.44-1.el7               

作为依赖被安装:
  mysql-community-client.x86_64 0:5.7.44-1.el7    mysql-community-common.x86_64 0:5.7.44-1.el7    net-tools.x86_64 0:2.0-0.25.20131004git.el7    perl.x86_64 4:5.16.3-299.el7_9        
  perl-Carp.noarch 0:1.26-244.el7                 perl-Encode.x86_64 0:2.51-7.el7                 perl-Exporter.noarch 0:5.68-3.el7              perl-File-Path.noarch 0:2.09-2.el7    
  perl-File-Temp.noarch 0:0.23.01-3.el7           perl-Filter.x86_64 0:1.49-3.el7                 perl-Getopt-Long.noarch 0:2.40-3.el7           perl-HTTP-Tiny.noarch 0:0.033-3.el7   
  perl-PathTools.x86_64 0:3.40-5.el7              perl-Pod-Escapes.noarch 1:1.04-299.el7_9        perl-Pod-Perldoc.noarch 0:3.20-4.el7           perl-Pod-Simple.noarch 1:3.28-4.el7   
  perl-Pod-Usage.noarch 0:1.63-3.el7              perl-Scalar-List-Utils.x86_64 0:1.27-248.el7    perl-Socket.x86_64 0:2.010-5.el7               perl-Storable.x86_64 0:2.45-3.el7     
  perl-Text-ParseWords.noarch 0:3.29-4.el7        perl-Time-HiRes.x86_64 4:1.9725-3.el7           perl-Time-Local.noarch 0:1.2300-2.el7          perl-constant.noarch 0:1.27-2.el7     
  perl-libs.x86_64 4:5.16.3-299.el7_9             perl-macros.x86_64 4:5.16.3-299.el7_9           perl-parent.noarch 1:0.225-244.el7             perl-podlators.noarch 0:2.5.1-3.el7   
  perl-threads.x86_64 0:1.87-4.el7                perl-threads-shared.x86_64 0:1.43-6.el7        

替代:
  mariadb-libs.x86_64 1:5.5.68-1.el7 

启动mysql

[root@stem-mysql tmp]# systemctl start mysqld

修改数据库管理员密码

[root@stem-mysql tmp]# grep 'temporary password' /var/log/mysqld.log
2023-12-14T00:01:07.587041Z 1 [Note] A temporary password is generated for root@localhost: *********

[root@stem-mysql tmp]#  mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.44

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> ALTER USER 'root'@'localhost' IDENTIFIED BY '**********'; 
Query OK, 0 rows affected (0.00 sec)

允许远程访问

[root@stem-mysql tmp]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.44 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> 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> select Host,User from user;
+-----------+---------------+
| Host      | User          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0.00 sec)

mysql> update user set Host='%' where User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

设置防火墙

[root@stem-mysql tmp]# firewall-cmd --state
running
[root@stem-mysql tmp]# firewall-cmd --zone=public --list-ports

[root@stem-mysql tmp]# firewall-cmd --zone=public --add-port=3306/tcp --permanen
success
[root@stem-mysql tmp]# setenforce 0
[root@stem-mysql tmp]# firewall-cmd --reload
success

相关推荐

  1. 笔记centos7安装mysql数据库

    2023-12-14 18:24:03       39 阅读
  2. 笔记centos7.9配置Nginx服务器

    2023-12-14 18:24:03       40 阅读
  3. linux/CentOS7安装mysql数据库

    2023-12-14 18:24:03       42 阅读
  4. 道—生产环境安装mysql

    2023-12-14 18:24:03       27 阅读
  5. CentOS根目录扩容

    2023-12-14 18:24:03       34 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-14 18:24:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-14 18:24:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-14 18:24:03       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-14 18:24:03       20 阅读

热门阅读

  1. 强烈推荐各类好用免费api

    2023-12-14 18:24:03       40 阅读
  2. 解决zabbix连接mysql 8数据库的异常问题

    2023-12-14 18:24:03       40 阅读
  3. android 上下轮播,广播 BulletinView

    2023-12-14 18:24:03       33 阅读
  4. android项目实战之选择图片并上传服务器

    2023-12-14 18:24:03       39 阅读
  5. 工作招聘

    2023-12-14 18:24:03       42 阅读
  6. 用php语言写一个自适应新闻单页面

    2023-12-14 18:24:03       42 阅读
  7. SVN优缺点详解及版本控制系统选型建议

    2023-12-14 18:24:03       49 阅读
  8. 安装ingress-nginx

    2023-12-14 18:24:03       43 阅读
  9. 超详细校园网络系统规划设计方案

    2023-12-14 18:24:03       32 阅读
  10. 浅谈时间序列预测中的时间步

    2023-12-14 18:24:03       66 阅读