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