运维笔记之centos7安装mysql数据库
2023-12-14 09:38:35
安装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
文章来源:https://blog.csdn.net/weixin_50648794/article/details/134986294
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!