Linux 安装 MySQL

[root@iZuf6j83unak4htk3braolZ opt]# rpm -qa | grep mysql  #查看是否已安装MySQL,无输出证明未安装

首先下载 yum 资源包,地址 https://dev.mysql.com/downloads/repo/yum/

        

[root@iZuf6j83unak4htk3braolZ opt]# wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm  #下载 yum 资源包
[root@iZuf6j83unak4htk3braolZ opt]# rpm -ivh mysql80-community-release-el8-1.noarch.rpm
[root@iZuf6j83unak4htk3braolZ opt]# yum update  #更新
[root@iZuf6j83unak4htk3braolZ opt]# yum install mysql-server  #安装 mysql-server
[root@iZuf6j83unak4htk3braolZ opt]# mysqld --initialize  #初始化
[root@iZuf6j83unak4htk3braolZ opt]# chown mysql:mysql -R /var/lib/mysql  #配置权限
[root@iZuf6j83unak4htk3braolZ opt]# systemctl start mysqld  #启动服务
[root@iZuf6j83unak4htk3braolZ opt]# systemctl status mysqld  #查看服务状态
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-08-17 16:50:42 CST; 12s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 23720 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 23743 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 12399)
Memory: 362.2M
CGroup: /system.slice/mysqld.service
└─23743 /usr/sbin/mysqld

Aug 17 16:50:40 iZuf6j83unak4htk3braolZ systemd[1]: Starting MySQL Server...
Aug 17 16:50:42 iZuf6j83unak4htk3braolZ systemd[1]: Started MySQL Server.

 查看 MySQL 安装默认密码

[root@iZuf6j83unak4htk3braolZ /]# grep "password" /var/log/mysqld.log
2021-08-17T08:48:13.097011Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: e!.&WSzp_2hB

进入 MySQL 

[root@iZuf6j83unak4htk3braolZ /]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 14
Server version: 8.0.26

Copyright (c) 2000, 2021, 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>

修改密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

ok,到此已经完成!

原文地址:https://www.cnblogs.com/netyts/p/15152810.html