二、MySQL数据库安装
2021/12/21 2:19:49
本文主要是介绍二、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>
大功告成
这篇关于二、MySQL数据库安装的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-23BinLog入门:新手必读的MySQL二进制日志指南
- 2024-10-23Binlog入门:MySQL数据库的日志管理指南
- 2024-10-22MySQL数据库入门教程:从安装到基本操作
- 2024-10-22MySQL读写分离入门教程:轻松实现数据库性能提升
- 2024-10-22MySQL分库分表入门教程
- 2024-10-22MySQL慢查询的诊断与优化指南
- 2024-10-22MySQL索引入门教程:快速理解与应用指南
- 2024-10-22MySQL基础入门教程:从安装到基本操作
- 2024-10-22MySQL数据库中的Binlog详解与操作教程
- 2024-10-12部署MySQL集群项目实战:新手入门教程