Mysql在线安装

Mysql在线安装

# 1.centos的yum 源中默认是没有mysql的,所以我们需要先去官网下载mysql的repo源并安装
# 2.安装 yum repo文件并更新 yum 缓存;
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
# 3.更新 yum 命令
yum clean all
yum makecache

# 卸载其他版本mysql(无需执行)
rpm -qa | grep -i mysql
rpm -e --nodeps   mysql-community-common-8.0.22-1.el7.x86_64
# 4.查看mysql yum仓库中mysql版本
yum repolist all | grep mysql
[root@k8s-master2 ~]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64  MySQL Cluster 7.5 Community  disabled
mysql-cluster-7.5-community-source  MySQL Cluster 7.5 Community  disabled
mysql-cluster-7.6-community/x86_64  MySQL Cluster 7.6 Community  disabled
mysql-cluster-7.6-community-source  MySQL Cluster 7.6 Community  disabled
mysql-cluster-8.0-community/x86_64  MySQL Cluster 8.0 Community  disabled
mysql-cluster-8.0-community-source  MySQL Cluster 8.0 Community  disabled
mysql-connectors-community/x86_64   MySQL Connectors Community   enabled:    175
mysql-connectors-community-source   MySQL Connectors Community - disabled
mysql-tools-community/x86_64        MySQL Tools Community        enabled:    120
mysql-tools-community-source        MySQL Tools Community - Sour disabled
mysql-tools-preview/x86_64          MySQL Tools Preview          disabled
mysql-tools-preview-source          MySQL Tools Preview - Source disabled
mysql55-community/x86_64            MySQL 5.5 Community Server   disabled
mysql55-community-source            MySQL 5.5 Community Server - disabled
mysql56-community/x86_64            MySQL 5.6 Community Server   disabled
mysql56-community-source            MySQL 5.6 Community Server - disabled
mysql57-community/x86_64            MySQL 5.7 Community Server   disabled
mysql57-community-source            MySQL 5.7 Community Server - disabled
mysql80-community/x86_64            MySQL 8.0 Community Server   enabled:    211
mysql80-community-source            MySQL 8.0 Community Server - disabled
# 5.使用 yum-config-manager 命令修改相应的版本为启用状态最新版本为禁用状态
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
# 或者可以编辑 mysql repo文件
vi /etc/yum.repos.d/mysql-community.repo 
# 将相应版本下的enabled改成 1 即可;
[root@k8s-master2 ~]# cat /etc/yum.repos.d/mysql-community.repo 
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.6
[mysql56-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

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

[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
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.5-community]
name=MySQL Cluster 7.5 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.6-community]
name=MySQL Cluster 7.6 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-8.0-community]
name=MySQL Cluster 8.0 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# 6.yum安装
yum install mysql-community-server -y
# 7.查看mysql状态
systemctl status mysqld.service
# 启动mysql
systemctl start mysqld.service
# 8.获取初始密码登录mysql
cat /var/log/mysqld.log | grep password
# 9.登录mysql
# 方式1
mysql -u root -p
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPassword';
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ideal@147258';
use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;

# 方式2
mysql -uroot -p
use mysql;
# Mysql默认不允许远程登录,所以需要开启远程访问权限
select user,authentication_string,host from user;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
# navicat 连接 mysql 出现`Client does not support authentication protocol requested by server`
alter user 'root'@'%' identified with mysql_native_password by '密码';
# 10.mysql服务加入开机启动项,并启动mysql进程
systemctl enable mysqld.service
systemctl restart mysqld.service

留下评论