说明:使用 Linux RPM 方式安装 MySQL必须使用root用户!

查看之前是否安装MySQL

1
rpm -qa | grep mysql

如果发现之前有安装过或者系统自带的MySQL版本,进行卸载

1
rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_64

MySQL官网 下载对应版本的rpm安装包:

下载地址:https://downloads.mysql.com/archives/community/
在这里插入图片描述

1
2
安装包:mysql-community-client-5.7.27-1.el6.x86_64.rpm 和 mysql-community-server-5.7.27-1.el6.x86_64.rpm
依赖包:mysql-community-common-5.7.27-1.el6.x86_64.rpm 和 mysql-community-libs-5.7.27-1.el6.x86_64.rpm

安装MySQL所需依赖

1
yum -y install perl-DBI libaio numactl

Linux环境下安装numactl

1
2
3
rpm -ivh perl-DBD-MySQL-4.023-6.el7.x86_64.rpm
or
yum -y install perl-DBI

安装 mysql-community-server-5.7.27-1.el6.x86_64.rpm 此处报错:

1
2
3
4
5
warning: MySQL-server-5.5.62-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libaio.so.1()(64bit) is needed by MySQL-server-5.5.62-1.el6.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.5.62-1.el6.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.5.62-1.el6.x86_64

解决办法:libaio.so.1()(64bit) is needed by MySQL-server 问题解决办法

1
yum -y install libaio

安装MySQL客户端 MySQL服务器

1
2
3
4
rpm -ivh ./mysql-community-common-5.7.27-1.el6.x86_64.rpm
rpm -ivh ./mysql-community-libs-5.7.27-1.el6.x86_64.rpm
rpm -ivh ./mysql-community-client-5.7.27-1.el6.x86_64.rpm
rpm -ivh ./mysql-community-server-5.7.27-1.el6.x86_64.rpm --nodeps --force

执行这个,自动识别安装顺序:

1
rpm -ivh mysql-community-*

启动mysql

1
service mysqld start

错误1、安装的libnuma.so.1它是32位系统使用的,我们需要64位系统使用的numactl-2.0.9-2.el6.x86_64.rpm

1
2
3
rpm -ivh numactl-2.0.9-2.el6.x86_64.rpm --nodeps --force
or
yum -y install numactl

在这里插入图片描述
error while loading shared libraries: libaio.so.1

场景:
在CentOS7.6系统下安装Mysql5.7时,初始化的时候报错:

1
mysqld: error while loading shared libraries: libaio.so.1:cannot open shared object file: No such file or directory

解决:
因为是新的系统,并没有安装所需要的依赖包

1
yum install -y libaio

然后重新初始化即可。

查询mysql数据库的初始化密码:

1
2
3
cat /var/log/mysqld.log | grep 'temporary password'
or
cat /var/log/mysqld.log

在这里插入图片描述

登录mysql

1
mysql -u root –p

修改密码及添加远程访问权限

1
2
3
4
5
mysql> set global validate_password_policy=0; 
mysql> set global validate_password_length=8;
mysql> set password=password('gbnc2012'); (可不做)
mysql> grant all privileges on *.* to 'root'@'%' identified by 'gbnc2012' with grant option;
mysql> flush privileges;
1
2
3
4
5
mysql> use mysql;
mysql> select Host, User from user;
mysql> update user set host = '%' where user='root';
mysql> flush privileges;
mysql> quit;

设置mysql开机自启

1
2
3
4
chkconfig --level 345 mysql on
or
chkconfig mysqld on
chkconfig --list | grep mysql # 查看mysql是否开机自启

参考链接

1、Centos6.7 rpm安装mysql数据库(cover—-大龙博客)
2、Centos6.7 系统安装MySQL
3、CentOS6.7安装及配置mysql