Mysql的安装
1、RPM安装方式
进入官网,将所需要的rpm包下载好:https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.36-1.el8.x86_64.rpm-bundle.tar
使用xftp上传到虚拟机上进行安装:
发现有报错,查看提示信息发现是缺少依赖,加上依赖包即可正常安装:
安装完成之后对服务状态和端口进行查看:
数据库初始密码在/var/log/mysqld.log下:
如果觉得这样找密码太难,还有以下两种方式:
初始密码只能做登录,修改密码后重新登录进行验证:
但是每次输入密码太麻烦,所以我们进入配置文件(/etc/my.cnf)进行编辑:
现在就不需要输入密码了
2、二进制安装
进入官网,将所需要的二进制包下载好:
https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.36-linux-glibc2.28-x86_64.tar.xz
下载好后使用xftp上传到虚拟机
官方下载手册:https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html
创建组和用户:
[root@openEuler-1 ~]# groupadd mysql
[root@openEuler-1 ~]# useradd -r -g mysql -s /bin/false mysql
[root@openEuler-1 ~]# grep mysql /etc/passwd
mysql:x:984:1001::/home/mysql:/bin/false
安装初始化:
[root@openEuler-1 ~]# tar xvf mysql-8.0.36-linux-glibc2.28-x86_64\ \(1\).tar.xz -C /usr/local/
# 解压到指定目录
[root@openEuler-1 ~]# ln -s /usr/local/mysql-8.0.36-linux-glibc2.28-x86_64/ /usr/local/mysql
#赋权,注意因为是软链接,路径最后一定要加"/"
[root@openEuler-1 ~]# chown -R mysql.mysql /usr/local/mysql/
[root@openEuler-1 ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2025-04-02T09:06:59.567347Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.36) initializing of server in progress as process 2015
2025-04-02T09:06:59.577671Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-04-02T09:07:00.077140Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-04-02T09:07:01.865314Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: /_/;+q6<=taL(初始密码)
[root@openEuler-1 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
提供配置文件和服务脚本:
[root@openEuler-1 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@openEuler-1 ~]# vim /etc/init.d/mysqld
#将46 47进行修改
46 basedir=/usr/local/mysql/
47 datadir=/usr/local/mysql/data/[root@openEuler-1 ~]# chkconfig --add mysqld
[root@openEuler-1 ~]# chkconfig mysqld on
启动服务:
[root@openEuler-1 ~]# systemctl start mysqld
[root@openEuler-1 ~]# systemctl is-active mysqld.service
active
配置环境变量:
[root@openEuler-1 ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin/' > /etc/profile.d/mysql.sh
[root@openEuler-1 ~]# source /etc/profile.d/mysql.sh
修改密码并测试: