因为云服务器升级,需要迁移到新的服务器平台,需要在新的服务器安装mysql,在此记录一下安装流程。
一、下载mysql
1、打开mysql官网,点击download
2、拉到页面最下方,点击
页面跳转之后,继续点击
页面跳转之后,可以下载最新版本的mysql,选择windows或者linux系统。如果需要下载历史版本,需要点击Archives。为了保持跟原系统版本一致,本文下载mysql的5.6.41版本。
页面跳转后,对linux版本,系统版本进行选择
点击Download按钮,下载tar包。
二、安装mysql 的 5.6.41版本
1、传输到linux服务器,解压tar包
2、卸载服务器自带的mysql
[root@enn-hadoop-mysql-server appadmin]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@enn-hadoop-mysql-server appadmin]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@enn-hadoop-mysql-server appadmin]#
3、安装openssl-devel插件,因为有些rpm安装包要依赖这个插件。
4、执行rpm安装包
rpm -ivh MySQL-client-5.6.41-1.el7.x86_64.rpm
rpm -ivh MySQL-devel-5.6.41-1.el7.x86_64.rpm
rpm -ivh MySQL-embedded-5.6.41-1.el7.x86_64.rpm
rpm -ivh MySQL-server-5.6.41-1.el7.x86_64.rpm
rpm -ivh MySQL-shared-5.6.41-1.el7.x86_64.rpm
rpm -ivh MySQL-shared-compat-5.6.41-1.el7.x86_64.rpm
rpm -ivh MySQL-test-5.6.41-1.el7.x86_64.rpm
注意保存运行日志,因为在日志里存在临时密码的文件目录:
A random root password has been set. You will find it in '/root/.mysql_secret'.
出现报错:
[root@enn-hadoop-mysql-server mysql-5.6.41]# rpm -ivh MySQL-shared-compat-5.6.41-1.el7.x86_64.rpm
warning: MySQL-shared-compat-5.6.41-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
mariadb-libs is obsoleted by MySQL-shared-compat-5.6.41-1.el7.x86_64
需要执行卸载lib包的命令
yum -y remove mariadb-libs
重新执行报错的命令即可。
5、执行mysql命令
[root@enn-hadoop-mysql-server mysql-5.6.41]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
Unit mysqld.service could not be found.
出现报错,执行find命令,查找mysql
[root@enn-hadoop-mysql-server mysql-5.6.41]# find / -name mysqld
/usr/sbin/mysqld
[root@enn-hadoop-mysql-server mysql-5.6.41]# find / -name mysql
/etc/logrotate.d/mysql
/etc/rc.d/init.d/mysql
/etc/selinux/targeted/active/modules/100/mysql
/var/lib/pcp/config/pmlogconf/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql
/usr/share/mysql
/usr/include/mysql
/usr/include/mysql/mysql
安装的是mysql,所以执行如下命令:
[root@enn-hadoop-mysql-server mysql-5.6.41]# service mysql status
ERROR! MySQL is not running
[root@enn-hadoop-mysql-server mysql-5.6.41]# service mysql start
Starting MySQL. SUCCESS!
6、登录mysql,修改密码
[root@enn-hadoop-mysql-server init.d]# cat /root/.mysql_secret
# The random password set for the root user at Thu Oct 26 09:18:34 2023 (local time): egVKiWF
[root@enn-hadoop-mysql-server init.d]# mysql -uroot -pegVKiWF
登录之后,将密码修改为123456
mysql> set password for 'root'@'localhost' = password('123456');
7、设置远程登录
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
mysql> flush privileges;
8、加入开机启动
[root@enn-hadoop-mysql-server mysql-5.6.41]chkconfig --add mysql
9、如果有防火墙的话,还需要开通3306端口
# 关闭防火墙
systemctl stop firewalld.service
# 对外开放3306端口
firewall-cmd --remove-port=3306/tcp --permanent 或者firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 重启防火墙
firewall-cmd --reload
三、安装mysql 的 5.7.25版本
前边步骤大体一样,安装rpm包的时候需要遵循以下依赖顺序:common ->libs ->client ->server
[root@enn-hadoop-cm mysql-5.7.25]# rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.25-1.e################################# [100%]
[root@enn-hadoop-cm mysql-5.7.25]# rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-5.7.25-1.el7################################# [100%]
[root@enn-hadoop-cm mysql-5.7.25]# rpm -ivh mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
warning: mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-compat-5.7.2################################# [100%]
[root@enn-hadoop-cm mysql-5.7.25]# rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-5.7.25-1.e################################# [100%]
[root@enn-hadoop-cm mysql-5.7.25]# rpm -ivh mysql-community-devel-5.7.25-1.el7.x86_64.rpm
warning: mysql-community-devel-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-devel-5.7.25-1.el################################# [100%]
[root@enn-hadoop-cm mysql-5.7.25]# rpm -ivh mysql-community-embedded-5.7.25-1.el7.x86_64.rpm
warning: mysql-community-embedded-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-embedded-5.7.25-1################################# [100%]
[root@enn-hadoop-cm mysql-5.7.25]# rpm -ivh mysql-community-embedded-compat-5.7.25-1.el7.x86_64.rpm
warning: mysql-community-embedded-compat-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-embedded-compat-5################################# [100%]
[root@enn-hadoop-cm mysql-5.7.25]# rpm -ivh mysql-community-embedded-devel-5.7.25-1.el7.x86_64.rpm
warning: mysql-community-embedded-devel-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-embedded-devel-5.################################# [100%]
[root@enn-hadoop-cm mysql-5.7.25]# rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-5.7.25-1.e################################# [100%]
[root@enn-hadoop-cm mysql-5.7.25]# rpm -ivh mysql-community-test-5.7.25-1.el7.x86_64.rpm
warning: mysql-community-test-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
perl(JSON) is needed by mysql-community-test-5.7.25-1.el7.x86_64
安装test模块出错,提示缺少依赖,那么我们就安装这个依赖:
[root@enn-hadoop-cm mysql-5.7.25]# yum install perl-JSON
安装完成之后,重新执行test模块
[root@enn-hadoop-cm mysql-5.7.25]# rpm -ivh mysql-community-test-5.7.25-1.el7.x86_64.rpm
warning: mysql-community-test-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-test-5.7.25-1.el7################################# [100%]
安装完成之后,可以查看配置文件
/etc/my.cnf里可以配置端口号
这个版本的命令有所不同,需要使用以下命令,不再是mysql,而是使用mysqld:
查看状态:systemctl status mysqld.service
重启:systemctl restart mysqld.service
启动:systemctl start mysqld.service
停止:systemctl stop mysqld.service查看状态:service mysqld status
重启:service mysqld restart
启动:service mysqld start
停止:service mysqld stop
而且在安装的过程中,没有发现临时密码,需要启动mysql之后,才能生成临时密码。
[root@enn-hadoop-cm log]# service mysqld start
[root@enn-hadoop-cm log]# grep 'password' /var/log/mysqld.log
2023-10-26T06:18:17.693671Z 1 [Note] A temporary password is generated for root@localhost: Qd1H4zpr!AjD遇到特殊字符的密码,报错
[root@enn-hadoop-cm log]# mysql -u root -pQd1H4zpr!AjD
bash: !AjD: event not found
需要转义[root@enn-hadoop-cm log]# mysql -u root -pQd1H4zpr\!AjD文章来源:https://www.toymoban.com/news/detail-773367.html
登录之后,设置密码,远程链接,修改防火墙,与之前一样。文章来源地址https://www.toymoban.com/news/detail-773367.html
到了这里,关于linux centos下载安装mysql详细教程(5.6.41和5.7.25)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!