首页 > 运维 > linux运维 > 正文

MySQL入门:Linux 6 RPM方式安装MySQL 8.0

雪夜
发布: 2025-07-11 10:24:16
原创
771人浏览过

如何下载和安装mysql rpm 程序包

1.建议从MySQL的官方网站下载软件,确保安全和可靠性。

下载链接:https://www.php.cn/link/06d86297d6e28d4637d60c86c2a2f5b6

MySQL入门:Linux 6 RPM方式安装MySQL 8.0

在下载页面,根据操作系统的版本选择适当的RPM包。此次选择的是适用于Linux 6的RPM包(RPM Bundle)。下载完成后,将其上传到Linux服务器上。使用Tar命令进行解压:

tar -xvf 包名
登录后复制

例如:

-bash-4.1$ tar -xvf mysql-8.0.23-1.el6.x86_64.rpm-bundle.tar
mysql-community-client-8.0.23-1.el6.x86_64.rpm
mysql-community-client-plugins-8.0.23-1.el6.x86_64.rpm
mysql-community-common-8.0.23-1.el6.x86_64.rpm
mysql-community-devel-8.0.23-1.el6.x86_64.rpm
mysql-community-libs-8.0.23-1.el6.x86_64.rpm
mysql-community-libs-compat-8.0.23-1.el6.x86_64.rpm
mysql-community-server-8.0.23-1.el6.x86_64.rpm
mysql-community-test-8.0.23-1.el6.x86_64.rpm
登录后复制

您可以通过rpm -qpl命令来查看RPM包中的文件内容。

shell> rpm -qpl mysql-community-server-version-distribution-arch.rpm
登录后复制

安装MySQL RPM包可以使用以下命令:

shell> sudo yum install mysql-community-{server,client,common,libs}-*
登录后复制

确认安装是否成功,可以通过以下步骤进行检查:

1.查看已安装的MySQL文件:

-bash-4.1$ rpm -qa | grep mysql
mysql-community-common-8.0.23-1.el6.x86_64
mysql-community-libs-8.0.23-1.el6.x86_64
mysql-community-server-8.0.23-1.el6.x86_64
mysql-community-client-8.0.23-1.el6.x86_64
mysql-community-client-plugins-8.0.23-1.el6.x86_64
mysql-community-libs-compat-8.0.23-1.el6.x86_64
登录后复制

2.检查MySQL服务的运行状态:

-bash-4.1$ service mysqld status
mysqld is stopped
登录后复制

注意:这里使用的是Oracle Linux 6,因此使用service命令来管理服务。

-bash-4.1$ service
Usage: service  | --status-all | [ service_name [ command | --full-restart ] ]
登录后复制

对于Linux 7及更高版本,可以使用systemctl来管理服务:

systemctl status mysqld.service
登录后复制

启动MySQL服务,在Linux 6上使用service命令:

火山方舟
火山方舟

火山引擎一站式大模型服务平台,已接入满血版DeepSeek

火山方舟 99
查看详情 火山方舟
-bash-4.1$ sudo service mysqld start
Initializing MySQL database:                               [  OK  ]
Starting mysqld:                                           [  OK  ]
-bash-4.1$ sudo service mysqld status
mysqld (pid  28030) is running...
登录后复制

对于Linux 7及更高版本,使用systemctl命令:

systemctl start mysqld
登录后复制

重置MySQL root用户密码:在服务器首次启动时,会自动创建超级用户账号'root'@'localhost'并设置临时密码,临时密码会存储在错误日志文件中。可以通过以下命令查看:

sudo grep 'temporary password' /var/log/mysqld.log
登录后复制

例如:

-bash-4.1$ sudo grep 'temporary password' /var/log/mysqld.log
2021-02-16T09:16:36.715031Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: u7hf5?5:4hG4
登录后复制

登录并使用临时密码,然后修改密码:

shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
登录后复制

例如:

-bash-4.1$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.23
<p>Copyright (c) 2000, 2021, Oracle and/or its affiliates.</p><p>Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.</p><p>Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.</p><p>mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
Query OK, 0 rows affected (0.03 sec)
登录后复制

登录确认:

-bash-4.1$ mysql -uroot -pMyNewPass4!
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 11
Server version: 8.0.23 MySQL Community Server - GPL</p><p>Copyright (c) 2000, 2021, Oracle and/or its affiliates.</p><p>Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.</p><p>Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.</p><p>mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)</p><p>mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select Host,User from user;
+-----------+------------------+
| Host      | User             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)</p><p>mysql> SELECT VERSION(), CURRENT_DATE;
+-----------+--------------+
| VERSION() | CURRENT_DATE |
+-----------+--------------+
| 8.0.23    | 2021-02-16   |
+-----------+--------------+
1 row in set (0.00 sec)
登录后复制

参考资料:https://www.php.cn/link/2804d14b1b70880c48b4cd4882e23ee0

以上就是MySQL入门:Linux 6 RPM方式安装MySQL 8.0的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号