centos7安装MySQL

本文详细记录了在CentOS7上安装MySQL5.7的步骤,包括解压安装包、使用yum安装、启动服务、查看服务状态以及设置初始密码的过程。在安装完成后,通过日志文件获取默认密码,并使用alter命令修改了root用户的密码,确保了系统的安全性。
摘要由CSDN通过智能技术生成

centos7安装MySQL
MySQL版本:mysql-5.7.32

解压软件包 tar xf mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar
查看解压后的MySQL安装包

[root@ansible shell100]# ll mysql-*
-rw-r--r--. 1 7155 31415  26460548 Sep 25 00:48 mysql-community-client-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    314936 Sep 25 00:48 mysql-community-common-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   3918236 Sep 25 00:48 mysql-community-devel-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  47479624 Sep 25 00:48 mysql-community-embedded-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  23263144 Sep 25 00:48 mysql-community-embedded-compat-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 130933732 Sep 25 00:48 mysql-community-embedded-devel-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   2457204 Sep 25 00:48 mysql-community-libs-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   1260336 Sep 25 00:48 mysql-community-libs-compat-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 181712536 Sep 25 00:49 mysql-community-server-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 124941892 Sep 25 00:49 mysql-community-test-5.7.32-1.el7.x86_64.rpm

安装软件

[root@ansible shell100]# yum -y install mysql-com*

软件安装完后启动MySQL服务

[root@ansible shell100]# systemctl start mysqld

查看服务是否启动

[root@ansible shell100]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-01-16 07:31:25 EST; 19min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html

MySQL启动后默认密码在mysqld.log中,使用默认密码登录,第一次登录的时候,提示修改密码,使用alter命令修改密码

[root@ansible shell100]# vim /var/log/mysqld.log 
[root@ansible shell100]# cat /var/log/mysqld.log |grep password
2021-01-16T12:31:23.086850Z 1 [Note] A temporary password is generated for root@localhost: Dv6oz.%&Yg-<
[root@ansible shell100]# cat /var/log/mysqld.log |awk '/password/{print $NF}'
Dv6oz.%&Yg-<

[root@ansible shell100]# mysql -uroot -p`cat /var/log/mysqld.log|awk '/password/{print $NF}'`
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.32

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> create database test;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user root@'localhost' identified by "Qwe123..";
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@ansible shell100]# mysql -uroot -p"Qwe123.."
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值