ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

二、MySQL数据库安装

2021-12-20 22:34:32  阅读:276  来源: 互联网

标签:8.0 27 root 数据库 MySQL community rpm mysql 安装


一、查看要安装mysql的Linux系统版本

[root@host125 etc]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"

二、下载MySQL rpm
https://dev.mysql.com/downloads/mysql/
在这里插入图片描述

三、安装
查看mysql官方安装教程文档

[root@host125 install]# ls -l mysql*
-rw-rw-r--. 1 wuzb wuzb 14692316 12月 19 09:14 mysql-community-client-8.0.27-1.el8.x86_64.rpm
-rw-rw-r--. 1 wuzb wuzb   645452 12月 19 09:03 mysql-community-common-8.0.27-1.el8.x86_64.rpm
-rw-rw-r--. 1 wuzb wuzb  1565372 12月 19 09:14 mysql-community-libs-8.0.27-1.el8.x86_64.rpm
-rw-rw-r--. 1 wuzb wuzb 55964292 12月 19 09:01 mysql-community-server-8.0.27-1.el8.x86_64.rpm
[root@host125 install]# 
[root@host125 install]# rpm -ivh mysql-community-common-8.0.27-1.el8.x86_64.rpm
警告:mysql-community-common-8.0.27-1.el8.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-8.0.27-1.e################################# [100%]

[root@host125 install]# rpm -ivh mysql-community-libs-8.0.27-1.el8.x86_64.rpm --force --nodeps
警告:mysql-community-libs-8.0.27-1.el8.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-8.0.27-1.el8################################# [100%]

[root@host125 install]# rpm -ivh mysql-community-client-8.0.27-1.el8.x86_64.rpm --force --nodeps
警告:mysql-community-client-8.0.27-1.el8.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-8.0.27-1.e################################# [100%]

[root@host125 install]# rpm -ivh mysql-community-client-8.0.27-1.el8.x86_64.rpm --force --nodeps
警告:mysql-community-client-8.0.27-1.el8.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-8.0.27-1.e################################# [100%]
[root@host125 install]# rpm -ivh mysql-community-server-8.0.27-1.el8.x86_64.rpm
警告:mysql-community-server-8.0.27-1.el8.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-server-8.0.27-1.e################################# [100%]
[/usr/lib/tmpfiles.d/mysql.conf:23] Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly.

安装完成后会创建以下内容
在这里插入图片描述

四、查看是否安装成功

[root@host125 install]# rpm -aq|grep mysql
mysql-community-common-8.0.27-1.el8.x86_64
mysql-community-client-8.0.27-1.el8.x86_64
mysql-community-server-8.0.27-1.el8.x86_64
mysql-community-libs-8.0.27-1.el8.x86_64

还有以下方式也可查看:

  • ps -ef | grep mysql

  • cat /etc/group | grep mysql

  • cat /etc/password | grep mysql

  • mysqladmin --version

五、初始化mysql

[root@host125 mysql]# mysqld --initialize //创建数据文件目录和mysql系统数据库 产生随机root密码

六、启动

[root@host125 mysql]# systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xe" for details.

哦豁,报错了。别急,查看报错日志

[root@host125 mysql]# view /var/log/mysqld.log
2021-12-19T14:31:55.430093Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.27) initializing of server in progress as process 35122
2021-12-19T14:31:55.450191Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-12-19T14:31:56.205957Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-12-19T14:31:57.546533Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2021-12-19T14:31:57.546567Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2021-12-19T14:31:57.673184Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: cxXe5.,sQ-v*
2021-12-19T14:33:17.353176Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.27) starting as process 35270
2021-12-19T14:33:17.367265Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9b23fb7f-60d8-11ec-b633-000c29f7125c.
mysqld: File '/var/lib/mysql/auto.cnf' not found (OS errno 13 - Permission denied)
2021-12-19T14:33:17.367427Z 0 [ERROR] [MY-010183] [Server] Failed to create file(file: '/var/lib/mysql/auto.cnf', errno 13)
2021-12-19T14:33:17.367457Z 0 [ERROR] [MY-010076] [Server] Initialization of the server's UUID failed because it could not be read from the auto.cnf file. If this is a new server, the initialization failed because it was not possible to generate a new UUID.
2021-12-19T14:33:17.367560Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-12-19T14:33:17.368344Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27)  MySQL Community Server - GPL.

从报错可以看出是因为没权限,赋权后重新启动

[root@host125 mysql]# chown -R mysql:mysql /var/lib/mysql/
[root@host125 mysql]# systemctl start mysqld
[root@host125 mysql]# ps -ef | grep mysqld
mysql       2579       1  2 08:58 ?        00:00:04 /usr/sbin/mysqld
root        2658    2164  0 09:00 pts/0    00:00:00 grep --color=auto mysqld
[root@host125 mysql]#

七、修改root用户密码

[root@host125 mysql]# grep 'temporary password' /var/log/mysqld.log
2021-12-19T14:31:57.673184Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: cxXe5.,sQ-v*
[root@host125 mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27

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

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> 

大功告成

标签:8.0,27,root,数据库,MySQL,community,rpm,mysql,安装
来源: https://blog.csdn.net/ahwuzebao/article/details/122030845

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有