MySql教程

CentOS 7 安装Mysql 8.0步骤(超级详细)

本文主要是介绍CentOS 7 安装Mysql 8.0步骤(超级详细),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、查看CentOS与Linux版本

[root@linuxtest ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@linuxtest ~]# cat /proc/version 
Linux version 3.10.0-862.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Fri Apr 20 16:44:24 UTC 2018

2、卸载mariadb

CentOS 7 内部集成了MariaDB,而安装Mysql会和MariaDB的文件冲突,所以需要先卸载掉MariaDB。
(MariaDB 是MySQL的一个分支,从MySQL被甲骨文收购之后开发的一个替代品,目前全部兼容MySQL。MariaDB 是原来MySQL 的作者 Michael Widenius 创办的公司所开发的免费开源的数据库服务器。CentOS 7/RHEL7中,默认已经不再提供mysql的安装源,取而代之的是mariadb数据库)

2.1 检查mariadb

rpm -qa | grep mariadb

2.2 卸载mariadb

rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64

3、安装Mysql

3.1 下载MySQL Yum Repository

在CentOS-7中安装MySQL需要配置下载源,不能直接使用yum安装
下载MySQL源官网地址:dev.mysql.com/downloads
根据系统版本选择下载相应的MySQL Yum源
选择下载对应的MySQL版本右键下载链接,选择复制链接

3.2 添加MySQL yum源

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm

3.3 安装MySQL

yum install mysql-community-server

3.4 启动MySQL服务

systemctl start mysqld

3.5 查看MySQL服务是否启动成功

[root@linuxtest software]# ps -ef| grep mysql
mysql     39794      1  6 16:00 ?        00:00:00 /usr/sbin/mysqld
root      39843  39566  0 16:00 pts/0    00:00:00 grep --color=auto mysql

3.6 查看MySQL临时密码

MySQL的临时密码存放在/var/log/mysqld.log文件下

[root@linuxtest software]# grep 'temporary password' /var/log/mysqld.log
2021-07-27T08:00:02.928720Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Mr#XMzmdd0kW

3.7 进入MySQL,修改临时密码

[root@linuxtest software]# 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.26

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.
mysql> alter user 'root'@'localhost' identified by 'Lab123!@#';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

3.8 使用新密码登陆MySQL

[root@linuxtest software]# 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.26 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.

3.9 创建新用户lab

mysql> create user 'lab'@'%' identified with mysql_native_password by 'Lab123!@#';
Query OK, 0 rows affected (0.00 sec)

3.10 赋予新用户lab权限

mysql> grant all on *.* to 'lab'@'%';
Query OK, 0 rows affected (0.00 sec)

3.11 退出MySQL

mysql> quit;
Bye

3.12 查看MySQL版本

启动MySQL,并设置为开机自启动

[root@linuxtest yum.repos.d]# mysql -V
mysql  Ver 8.0.26 for Linux on x86_64 (MySQL Community Server - GPL)
[root@linuxtest yum.repos.d]# systemctl start mysqld
[root@linuxtest yum.repos.d]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-07-27 16:00:05 CST; 38min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 39718 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 39794 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─39794 /usr/sbin/mysqld

Jul 27 16:00:01 linuxtest systemd[1]: Starting MySQL Server...
Jul 27 16:00:05 linuxtest systemd[1]: Started MySQL Server.
[root@linuxtest yum.repos.d]# systemctl enable mysqld

完成MySQL安装和帐号、密码配置,可以选择一款客户端软件连接MySQL了!

这篇关于CentOS 7 安装Mysql 8.0步骤(超级详细)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!