数据库MySQL安装方法:官网下载安装、国内镜像源安装

一、官网下载安装

(MySQL :: Download MySQL Yum Repository)

下载rpm包,上传到虚拟机上(rz命令)

[root@localhost ~]# ls  //在官网下载rpm包
anaconda-ks.cfg  mysql80-community-release-el7-7.noarch.rpm
[root@localhost ~]# yum -y install mysql80-community-release-el7-7.noarch.rpm 
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo  mysql-community-debuginfo.repo  mysql-community-source.repo
epel.repo         mysql-community.repo
[root@localhost ~]# yum list | grep mysql
[root@localhost ~]# yum makecacha
[root@localhost ~]# yum -y install mysql-community* //这里可能会报一个错误,执行下面的语句即可

[root@localhost ~]# yum -y install mysql-community* --skip-broken
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# grep password /var/log/mysql.log //看一下数据库的密码
2022-10-05T07:43:46.324849Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 7T.q#wtouUwz
[root@localhost ~]# mysqladmin -uroot -p'7T.q#wtouUwz' password 'Qian@123' //修改数据的密码
[root@localhost ~]# mysql -uroot -p'Qian@123' //登录数据库
mysql> exit  //退出数据库
Bye

二、国内镜像源安装

[root@localhost ~]# systemctl stop firewalld  //关闭防火墙
[root@localhost ~]# systemctl disable firewalld  //开机禁用防火墙
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0    //关闭selinux

1.访问国内mysql镜像站

USTC Open Source Software Mirror(中国科学技术大学开源软件镜像)也可以使用其他的镜像站下载

2.下载软件包

[root@localhost ~]# wget https://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-server-5.7.36-1.el7.x86_64.rpm
[root@localhost ~]# wget https://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-client-5.7.36-1.el7.x86_64.rpm
[root@localhost ~]# wget https://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-common-5.7.36-1.el7.x86_64.rpm
[root@localhost ~]# wget https://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-libs-5.7.36-1.el7.x86_64.rpm

3.安装相关软件

[root@localhost ~]# yum install -y net-tools.x86_64 libaio.x86_64 perl.x86_64

4.安装MySQL服务器

[root@localhost ~]# yum install -y mysql-community*
安装的时候可能会发生下面的报错的信息,根据提示卸载掉冲突的软件包,再安装
[root@localhost ~]# yum remove -y mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# yum install -y mysql-community*

数据库MySQL安装方法:官网下载安装、国内镜像源安装_第1张图片

数据库MySQL安装方法:官网下载安装、国内镜像源安装_第2张图片

5.启动MySQL服务器

[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2022-10-06 05:16:29 EDT; 16s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 2259 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─2259 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.p...

Oct 06 05:16:24 localhost.localdomain systemd[1]: Starting MySQL Server...
Oct 06 05:16:29 localhost.localdomain systemd[1]: Started MySQL Server.

6.查询MySQL服务器默认密码

[root@localhost ~]# grep password /var/log/mysqld.log 
2022-10-06T09:16:26.980714Z 1 [Note] A temporary password is generated for root@localhost: grim85OQ=lpa    //grim85OQ=lpa这个就是密码

7.修改MySQL服务器密码

[root@localhost ~]# mysqladmin -uroot -p'grim85OQ=lpa' password 'Linn@123'

8.登录MySQL系统

[root@localhost ~]# mysql -uroot -p'Linn@123'

9.查找默认数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

 

你可能感兴趣的:(mysql,数据库)