centos7安装mysql8.0.31

本文档详细介绍了如何在CentOS7系统中卸载预装的MariaDB,然后下载并安装MySQL8.0的完整过程。包括通过RPM命令卸载MariaDB,下载MySQL的rpm包,使用YUM安装相关组件,修改配置文件,初始化数据库,设置远程访问权限,更新密码,以及开启防火墙允许3306端口的访问。这为需要在 CentOS7 上部署 MySQL 8.0 的用户提供了一套完整的操作指南。

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

1. 卸载mariadb

centos7默认安装了mariadb, 会造成依赖冲突,按下列方式进行卸载:

[root@localhost ~]# 
[root@localhost ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# 
[root@localhost ~]# rpm -e mariadb-libs --nodeps
[root@localhost ~]# 
[root@localhost ~]# rpm -qa | grep mariadb
[root@localhost ~]# 
[root@localhost ~]# 

2. 下载并解压


[root@localhost /]# cd /var/local
[root@localhost local]# 
[root@localhost local]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar

[root@localhost local]# mkdir mysql-8.0.31
[root@localhost local]# 
[root@localhost local]# tar -xvf mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar -C mysql-8.0.31
mysql-community-client-8.0.31-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm
mysql-community-common-8.0.31-1.el7.x86_64.rpm
mysql-community-debuginfo-8.0.31-1.el7.x86_64.rpm
mysql-community-devel-8.0.31-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.31-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm
mysql-community-libs-8.0.31-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.31-1.el7.x86_64.rpm
mysql-community-server-8.0.31-1.el7.x86_64.rpm
mysql-community-server-debug-8.0.31-1.el7.x86_64.rpm
mysql-community-test-8.0.31-1.el7.x86_64.rpm
[root@localhost local]# 

3. 安装

[root@localhost local]# cd mysql-8.0.31
[root@localhost mysql-8.0.31]#
[root@localhost mysql-8.0.31]# yum install -y perl.x86_64
[root@localhost mysql-8.0.31]# yum install net-tools
[root@localhost mysql-8.0.31]# yum install -y perl-Module-Install.noarch
[root@localhost mysql-8.0.31]# rpm -ivh mysql-community-common-8.0.31-1.el7.x86_64.rpm
[root@localhost mysql-8.0.31]# rpm -ivh mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm
[root@localhost mysql-8.0.31]# rpm -ivh mysql-community-libs-8.0.31-1.el7.x86_64.rpm
[root@localhost mysql-8.0.31]# rpm -ivh mysql-community-client-8.0.31-1.el7.x86_64.rpm
[root@localhost mysql-8.0.31]# rpm -ivh mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm
[root@localhost mysql-8.0.31]# rpm -ivh mysql-community-server-8.0.31-1.el7.x86_64.rpm
[root@localhost mysql-8.0.31]# 

4. 修改/etc/my.cnf

log_timestamps = SYSTEM
#忽略大小写
lower-case-table-names=1

5. 初始化

mysqld --initialize --console

#忽略大小写 
#mysqld --initialize --user=mysql --lower-case-table-names=1

6. 授权

chown -R mysql:mysql /var/lib/mysql/

7. 启动并查看状态

[root@localhost mysql-8.0.31]# systemctl start mysqld
[root@localhost mysql-8.0.31]# 
[root@localhost mysql-8.0.31]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2022-11-18 06:59:53 CST; 1s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1595 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1668 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─1668 /usr/sbin/mysqld

11月 18 06:59:48 single systemd[1]: Starting MySQL Server...
11月 18 06:59:53 single systemd[1]: Started MySQL Server.
[root@localhost mysql-8.0.31]# 

8. 首次登录

[root@localhost mysql-8.0.31]# cat /var/log/mysqld.log | grep password
2022-11-18T06:59:49.967603+08:00 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: d:fAhy+G)8uw
[root@localhost mysql-8.0.31]# 
[root@localhost mysql-8.0.31]# mysql -u root -pd:fAhy+G\)8uw
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 8
Server version: 8.0.31

Copyright (c) 2000, 2022, 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>

9. 修改远程访问权限以及密码

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 user, host from user where user='root';
+------+-----------+
| user | host      |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.00 sec)

mysql> update user set host ='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
mysql> alter user 'root'@'%' identified with mysql_native_password by '123456';
mysql> grant all privileges on *.* to 'root'@'%';
mysql> flush privileges;

10. 开放端口

mysql> exit

[root@localhost mysql-8.0.31]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@localhost mysql-8.0.31]# success
[root@localhost mysql-8.0.31]# firewall-cmd --reload
[root@localhost mysql-8.0.31]# systemctl restart firewalld.service
 

现在就可以连接啦  小伙伴们记得关注哦 笔芯 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值