Linux(CentOS)使用安装包安装MySQL

本文详细介绍了在CentOS系统上通过下载安装包的方式安装MySQL8.0.25,包括解压、安装各个组件、处理警告、初始化数据库、设置root用户密码以及授予远程访问权限的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Linux(CentOS)使用安装包安装MySQL

1、解压上传安装包

tar -xvf mysql-8.0.25-1.el7.x86_64.rpm-bundle.tar

2、安装

  
[root@ueserver217 mysqldev]# rpm -ivh mysql-community-common-8.0.25-1.el7.x86_64.rpm --nodeps --force
警告:mysql-community-common-8.0.25-1.el7.x86_64.rpm:V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-8.0.25-1.e################################# [100%]
[root@ueserver217 mysqldev]# rpm -ivh mysql-community-libs-compat-8.0.25-1.el7.x86_64.rpm --nodeps --force 
警告:mysql-community-libs-compat-8.0.25-1.el7.x86_64.rpm:V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-compat-8.0.2################################# [100%]
/sbin/ldconfig: 文件 /lib/libsecx.so 己被截断

/sbin/ldconfig: 文件 /lib64/libsecx.so 己被截断

[root@ueserver217 mysqldev]# rpm -ivh mysql-community-client-8.0.25-1.el7.x86_64.rpm --nodeps --force 
警告:mysql-community-client-8.0.25-1.el7.x86_64.rpm:V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-8.0.25-1.e################################# [100%]
[root@ueserver217 mysqldev]# rpm -ivh mysql-community-server-8.0.25-1.el7.x86_64.rpm --nodeps --force 
警告:mysql-community-server-8.0.25-1.el7.x86_64.rpm:V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-server-8.0.25-1.e################################# [100%]
[root@ueserver217 mysqldev]#  rpm -qa | grep mysql
mysql-community-libs-compat-8.0.25-1.el7.x86_64
mysql-community-server-8.0.25-1.el7.x86_64
mysql-community-client-8.0.25-1.el7.x86_64
mysql-community-common-8.0.25-1.el7.x86_64
[root@ueserver217 mysqldev]# mysqld --initialize

[root@ueserver217 mysqldev]# 
[root@ueserver217 mysqldev]# 
[root@ueserver217 mysqldev]# mysqld --initialize;
[root@ueserver217 mysqldev]# chown mysql:mysql /var/lib/mysql -R;
[root@ueserver217 mysqldev]# systemctl start mysqld.service;
^C
[root@ueserver217 mysqldev]# ^C
[root@ueserver217 mysqldev]# chown mysql:mysql /var/lib/mysql -R
[root@ueserver217 mysqldev]# systemctl start mysqld.service
[root@ueserver217 mysqldev]# systemctl  enable mysqld
[root@ueserver217 mysqldev]# cat /var/log/mysqld.log | grep password 
2023-11-24T08:12:57.014010Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: =&Zy%;Xk1roe
[root@ueserver217 mysqldev]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@ueserver217 mysqldev]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.25

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 WITH mysql_native_password BY 'root'
    -> ;
Query OK, 0 rows affected (0.10 sec)

mysql> exit
Bye
[root@ueserver217 mysqldev]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.25 MySQL Community Server - GPL

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> exit
Bye

6、 安装完成后,无法被他人连接

Host ‘xxx.xxx.xxx.xxx’ is not allowed connect to this mysql server

6.1、授权法

-- 登录
mysql -u root -p rootpassword;

--  赋予给指定IP连接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'xxx.xxx.xxx.xxx' IDENTIFIED BY 'rootPassword' WITH GRANT OPTION;
-- 刷新数据库命令必须执行!!
FLUSH   PRIVILEGES;

示例


[root@ueserver217 mysqldev]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.25 MySQL Community Server - GPL

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> GRANT ALL PRIVILEGES ON *.* TO 'root'@'xxx.xxx.xxx.xxx' IDENTIFIED BY 'root' WITH GRANT OPTION;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY 'root' WITH GRANT OPTION' at line 1
mysql> exit
Bye
[root@ueserver217 mysqldev]# clear
[root@ueserver217 mysqldev]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 8.0.25 MySQL Community Server - GPL

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> FLUSH   PRIVILEGES;
Query OK, 0 rows affected (0.09 sec)

mysql> exit
Bye
### 上传使用安装包CentOS安装MySQL #### 准备工作 为了确保顺利安装MySQL,在开始之前需确认已准备好相应的环境配置。这括但不限于拥有管理员权限以及网络连接正常以便于下载必要的依赖项。 #### 下载MySQL安装包 访问官方提供的链接[^1],选择适合Linux系统的`.tar.gz`压缩文件进行下载。对于特定版本的需求,如本案例中的MySQL 5.6版,应当精确匹配以避免兼容性问题。 #### 解压与解绑RPM(如果适用) 如果是采用RPM格式的捆绑,则需要先对其进行解捆操作。例如,针对MySQL 5.6版本的离线安装包,可以执行如下命令完成此过程: ```bash [root@localhost mysql]# tar -xvf MySQL-5.6.46-1.el7.x86_64.rpm-bundle.tar ``` #### 创建数据存储目录及设置权限 建立专门用于存放数据库文件的数据目录,并调整其所有权给指定的服务账户,通常命名为`mysql`。具体做法如下所示: ```bash mkdir -R /data/mysql #赋予权限 ``` #### 配置初始化参数文件 编辑全局配置文件`my.cnf`来定义初始启动所需的各项参数设定。可以通过文本编辑器打开该文件来进行修改: ```bash vim /etc/my.cnf ``` 在此过程中可根据实际需求自定义各类选项,比如端口号、字符集编码等重要属性。 #### 安装MySQL服务 根据所获取到的具体安装包形式采取不同的安装策略。若是基于源码编译或是二进制分发的形式,则可能涉及到更多复杂的前置条件准备;而直接利用预构建好的二进制则相对简单得多。这里假设已经完成了上述准备工作: ##### 对于Tarball(.tar.gz)类型的安装包 提取归档内的所有组件至目标位置,并按照官方文档指示继续后续步骤。 ```bash tar zxvf mysql-VERSION-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ ln -s /usr/local/mysql-VERSION-linux-glibc2.12-x86_64 /usr/local/mysql cd /usr/local/mysql ./scripts/mysql_install_db --user=mysql cp support-files/mysql.server /etc/init.d/mysql chkconfig --add mysql service mysql start ``` ##### 使用RPM方式安装 可以直接通过yum工具或者其他方法安装rpm集合里的各个单个软件。注意要遵循正确的依赖关系顺序依次处理每一个rpm文件。 ```bash rpm -ivh MySQL-server-*.rpm rpm -ivh MySQL-client-*.rpm ... ``` #### 启动MySQL服务器并与之交互 一旦成功部署完毕之后就可以尝试启动mysqld进程并且验证是否能够正常使用客户端程序登录管理新设立起来的实例了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值