Linux中安装mysql

本文介绍了在Linux系统中通过本地仓库安装MySQL服务器的方法一,以及使用本地下载并手动安装的步骤,包括下载、解压、依赖包安装、临时密码获取和密码重置的过程。
摘要由CSDN通过智能技术生成

方法一:使用本地仓库的方式进行安装(省时省力)

[root@localhost ~]# dnf install mysql-server

[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# 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.32 Source distribution

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

方法二:使用本地下载方式进行安装

链接地址:

https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.35-1.el9.x86_64.rpm-bundle.tar  

第一步:下载mysql

[root@localhost ~]# cat /etc/redhat-release		# 查看当前Linux版本
Red Hat Enterprise Linux release 9.3 (Plow)
[root@localhost ~]# ll
总用量 4
drwxr-xr-x. 2 root root    6  1月  8 11:39 公共
drwxr-xr-x. 2 root root    6  1月  8 11:39 模板
drwxr-xr-x. 2 root root    6  1月  8 11:39 视频
drwxr-xr-x. 2 root root    6  1月  8 11:39 图片
drwxr-xr-x. 2 root root    6  1月  8 11:39 文档
drwxr-xr-x. 2 root root    6  1月  8 11:39 下载
drwxr-xr-x. 2 root root    6  1月  8 11:39 音乐
drwxr-xr-x. 2 root root    6  1月  8 11:39 桌面
-rw-------. 1 root root 1354  1月  8 11:38 anaconda-ks.cfg
[root@localhost ~]# cd 下载/
[root@localhost 下载]# ll
总用量 0					# 从官方网站下载完以后,用xftp拖移到这个目录下

[root@localhost ~]# ll
总用量 4
drwxr-xr-x. 2 root root    6  1月  8 11:39 公共
drwxr-xr-x. 2 root root    6  1月  8 11:39 模板
drwxr-xr-x. 2 root root    6  1月  8 11:39 视频
drwxr-xr-x. 2 root root    6  1月  8 11:39 图片
drwxr-xr-x. 2 root root    6  1月  8 11:39 文档
drwxr-xr-x. 2 root root    6  1月  8 11:39 下载
drwxr-xr-x. 2 root root    6  1月  8 11:39 音乐
drwxr-xr-x. 2 root root    6  1月  8 11:39 桌面
-rw-------. 1 root root 1354  1月  8 11:38 anaconda-ks.cfg
[root@localhost ~]# cd 下载/
# 进入到下载目录下面 

 第二步:下载完成后进行解压

[root@localhost 下载]# tar xvf mysql-8.0.35-1.el9.x86_64.rpm-bundle.tar 

选中挑选以上数据包

#[root@localhost mysql]# dnf localinstall mysql-community-server-8.0.35-
1.el9.x86_64.rpm \
mysql-community-client-8.0.35-1.el9.x86_64.rpm \
mysql-community-common-8.0.35-1.el9.x86_64.rpm \
mysql-community-icu-data-files-8.0.35-1.el9.x86_64.rpm \
mysql-community-client-plugins-8.0.35-1.el9.x86_64.rpm \
mysql-community-libs-8.0.35-1.el9.x86_64.rpm
[root@localhost mysql]# systemctl start mysqld		# 启动

第三步:查看密码进行登录

1. [root@localhost mysql]# grep password /var/log/mysqld.log    # 查看临时密码
2024-01-08T14:19:16.356413Z 6 [Note] [MY-010454] [Server] A temporarypassword is generated for root@localhost: Rwjyfwf56e!u

2. [root@localhost mysql]# mysql -uroot -p
Enter password:        # 输入临时密码

输入后就可以成功登录了,第一次登录后,在执行语句之前,必须使用ALTER USER语句重置密码

第五步:重置密码

mysql> alter user 'root'@'localhost' identified by '#Openlab123';
Query OK, 0 rows affected (0.01 sec)


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

成功登录

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值