系统:centos7.x和Centos8.x
mysql版本:mysql5.6或5.7
提示:如果有重要数据请务必做好备份或快照,以免数据丢失无法找回。如果之前安装过mysql,再次安装可能会失败。
方法1:
从官网下载RPM包安装。
1、访问:https://downloads.mysql.com/archives/community/ 选择版本及操作系统,如图。
说明:如果安装mysql5.7,选择5.7即可。方法一样。 2、复制下载地址,在服务器用wget下载。(如果安装mysql,下载对应安装包并解压即可)
解压:wget https://downloads.mysql.com/archives/get/p/23/file/MySQL-5.6.51-1.el7.x86_64.rpm-bundle.tar
3、执行如下 命令安装所有rpm包tar -xvf MySQL-5.6.51-1.el7.x86_64.rpm-bundle.tar
sudo rpm -ivh *.rpm
有报错:[root@blog.tag.gg~]# sudo rpm -ivh *.rpm
warning: MySQL-client-5.6.51-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libaio.so.1()(64bit) is needed by MySQL-embedded-5.6.51-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-embedded-5.6.51-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-embedded-5.6.51-1.el7.x86_64
libaio.so.1()(64bit) is needed by MySQL-server-5.6.51-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.51-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.6.51-1.el7.x86_64
perl(Data::Dumper) is needed by MySQL-server-5.6.51-1.el7.x86_64
mariadb-libs is obsoleted by MySQL-shared-compat-5.6.51-1.el7.x86_64
perl(Data::Dumper) is needed by MySQL-test-5.6.51-1.el7.x86_64
解决报错:
1、warning: MySQL-client-5.6.51-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
这个是缺少签名证书。在安装命令后面添加参数“ --force --nodeps ”即可
2、报错 “ libaio.so.1”sudo rpm -ivh *.rpm --force --nodeps
执行如下命令安装组件后再安装。
3、报错:FATAL ERROR: please install the following Perl modules before executing /usr/bin/mysql_install_db:yum -y install libaio
Data::Dumper
执行如下命令:
至此,mysql安装完成,执行如下命令启动数据库yum install -y perl-Module-Install.noarch
4、启动Mysql:
或service mysql restart
启动如果有报错:service mysqld restart
ERROR! The server quit without updating PID file (/var/lib/mysql/xx.pid)
提示:务必做好备份或快照,不然数据丢失无法找回。
一般是 默认安装了一些有关mysql和mariadb的文件 ,执行 find / -name mysql 和 find / -name mariadb 找到相应文件删除后再安装。
安装后若还是提示一样报错。则参考如下处理:
1、检查/var/lib/mysql目录权限是否正确,一般目录权限是mysql账户。
2、看下/var/lib/mysql/目录下面是否有生成“xxx.err”这个错误日志文件,若有,打开这个日志文件看下是否有报错,例如我的报错是如下:
根据 error 中的提示 我们可以使用 mysql_upgrade 来修复问题:mysqld: Table 'mysql.plugin' doesn't exist
120221 2:17:24 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
显示如图则表示修复成功,修复成功后再启动数据库。 5、启动myql后根据上面截图提示输入如下命令初始化数据库(设置数据库root密码等操作)mysql_install_db --user=mysql
初始化方法可参考另一篇教程:https://blog.tag.gg/showinfo-13-36186-0.html 的第三步骤:mysql_secure_installation
方法2:
通过yum安装:
1、安装源:
2、执行如下命令安装mysql5.6最新版wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
3、启动mysqlsudo yum install mysql-community-server
4、初始化数据库(设置mysql的root密码等设置)sudo systemctl start mysqld
sudo systemctl enable mysqld
初始化方法可参考另一篇教程:https://blog.tag.gg/showinfo-13-36186-0.html 的第三步骤:
yum方式安装mysql5.7方法:
1、下载5.7的源并安装
2、安装mysql5.7:wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm
安装若提示报错:sudo yum install mysql-community-server
The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.
则执行如下命令安装:
3、启动数据库:sudo yum install mysql-community-server --nogpgcheck
4、查看默认的数据库root密码:后面建议修改一下 。密码不要太简单。sudo systemctl start mysqld
sudo systemctl enable mysqld
登录到数据库后若要修改数据库root密码,可执行如下命令。sudo grep 'temporary password' /var/log/mysqld.log
登录数据库:
修改密码:mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'ceshi@7889A';
文章评论 本文章有个评论