[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
CentOS 7 内部集成了MariaDB,而安装Mysql会和MariaDB的文件冲突,所以需要先卸载掉MariaDB。
(MariaDB 是MySQL的一个分支,从MySQL被甲骨文收购之后开发的一个替代品,目前全部兼容MySQL。MariaDB 是原来MySQL 的作者 Michael Widenius 创办的公司所开发的免费开源的数据库服务器。CentOS 7/RHEL7中,默认已经不再提供mysql的安装源,取而代之的是mariadb数据库)
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
在CentOS-7中安装MySQL需要配置下载源,不能直接使用yum安装
下载MySQL源官网地址:dev.mysql.com/downloads
根据系统版本选择下载相应的MySQL Yum源
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm rpm -ivh mysql80-community-release-el7-3.noarch.rpm
yum install mysql-community-server
systemctl start mysqld
[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
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
[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)
[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.
mysql> create user 'lab'@'%' identified with mysql_native_password by 'Lab123!@#'; Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to 'lab'@'%'; Query OK, 0 rows affected (0.00 sec)
mysql> quit; Bye
启动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了!