CentOS学习之 yum 安装 mysql5.6

查看操作系统版本
cat /etc/redhat-release
内核版本
uname -r
系统版本
 uname -m
查询 CentOS 7 自带的 Mariadb
rpm -qa | grep mariadb
卸载 Mariadb
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
查询是否已安装 MySQL
rpm -qa | grep mysql

如果已安装低版本的 MySQL

1.停止 MySQL 服务
systemctl stop mysqld
2.关闭 MySQL 服务开机启动
systemctl disable mysqld
3.卸载低版本的 MySQL
rpm -e --nodeps 名称
获取 Yum 源

MySQL 官网下载需要的版本

Yum Download

下载的包名

mysql80-community-release-el7-2.noarch.rpm

下载该源到服务器

wget  ~/http://repo.mysql.com/mysql80-community-release-el7-2.noarch.rpm
验证MD5
md5sum ~/mysql80-community-release-el7-2.noarch.rpm
MD5 值和官方提供的一致,是安全的,添加该源:
yum -y localinstall ~/mysql80-community-release-el7-2.noarch.rpm
查看当前源中所有MySQL软件包
yum repolist all | grep mysql

查看可以安装的软件包

yum repolist enabled | grep mysql

因为我们是需要安装MySQL5.6,所以需要去修改下源设置

vim /etc/yum.repos.d/mysql-community.repo
[mysql57-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

#将enabled=0改成enabled=1

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1

#将enabled=1改成enabled=0

现在查看MySQL安装版本

yum repolist enabled | grep mysql
安装 MySQL5.6
yum -y install mysql-community-server
查看安装的 MySQL 版本
mysqld -V

mysqld Ver 5.6.43 for Linux on x86_64 (MySQL Community Server (GPL))

至此MySQL安装成功

MySQL设置开机启动
systemctl enable mysqld
MySQL常用命令
#启动MySQL
systemctl start mysqld
#停止MySQL
systemctl stop mysqld
#重启
systemctl restart mysqld
#MySQL状态
systemctl status mysqld
安装中出现的错误

1.报错提示:

[Warning] TIMESTAMP with implicit DEFAULT value is deprecated.

Please use --explicit_defaults_for_timestamp
server option (see documentation for more details)

解决办法:

my.cnf

在[mysqld]下加上这个配置即可
explicit_defaults_for_timestamp=true

2.报错提示:

[ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

解决办法:

my.cnf

在[mysqld]后面加入
user=mysql

3.报错提示:

[Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)

[Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)

解决办法:

第一步:修改/etc/security/limits.conf

mysql hard nofile 65535
mysql soft nofile 65535

第二步:修改mysql的服务/lib/systemd/system/mysqld.service文件

LimitNOFILE=65535

第三步:重启mysql服务
systemctl restart mysqld
添加新评论