Linux在线yum方式安装mysql5.7(适用于mysql8.0)

Linux下软件常见部署方式有三种:yum安装、rpm安装以及编译安装。由于离线、编译需要先下载多个文件再安装,步骤较多,所以整理了一下在线安装mysql的方法,文中系统为CentOS7.9版本。

1.配置好yum源,包括epel源

wget -qO /etc/yum.repos.d/epel.repo http://mirrors.myhuaweicloud.com/repo/epel-7.repo
yum makecache
yum install epel-release -y >/dev/null 2>&1
yum repolist all | grep mysql
#如果输入后没有反应,则表示本地还没有mysql的源,需要去官网下载了。

使用官方yum仓库,官方下载链接

Linux在线yum方式安装mysql5.7(适用于mysql8.0)
Linux在线yum方式安装mysql5.7(适用于mysql8.0)
wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
yum install mysql80-community-release-el7-7.noarch.rpm

2. 生成yum源缓存并查看mysql版本

[root@localhost ~]# yum makecache
[root@localhost ~]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64           MySQL Cluster 7.5 C disabled
mysql-cluster-7.5-community-source           MySQL Cluster 7.5 C disabled
mysql-cluster-7.6-community/x86_64           MySQL Cluster 7.6 C disabled
mysql-cluster-7.6-community-source           MySQL Cluster 7.6 C disabled
mysql-cluster-8.0-community/x86_64           MySQL Cluster 8.0 C disabled
mysql-cluster-8.0-community-debuginfo/x86_64 MySQL Cluster 8.0 C disabled
mysql-cluster-8.0-community-source           MySQL Cluster 8.0 C disabled
mysql-connectors-community/x86_64            MySQL Connectors Co enabled:    206
mysql-connectors-community-debuginfo/x86_64  MySQL Connectors Co disabled
mysql-connectors-community-source            MySQL Connectors Co disabled
mysql-tools-community/x86_64                 MySQL Tools Communi enabled:     94
mysql-tools-community-debuginfo/x86_64       MySQL Tools Communi disabled
mysql-tools-community-source                 MySQL Tools Communi disabled
mysql-tools-preview/x86_64                   MySQL Tools Preview disabled
mysql-tools-preview-source                   MySQL Tools Preview disabled
mysql57-community/x86_64                     MySQL 5.7 Community disabled
mysql57-community-source                     MySQL 5.7 Community disabled
mysql80-community/x86_64                     MySQL 8.0 Community enabled:    367
mysql80-community-debuginfo/x86_64           MySQL 8.0 Community disabled
mysql80-community-source                     MySQL 8.0 Community disabled

从enable状态来看,默认启用的是最新8.0版本,如果想要使用5.7版本,需要使用到YUM 管理工具包,此包提供了 yum-config-manager 命令工具:

[root@localhost ~]# yum -y install yum-utils
[root@localhost ~]# yum-config-manager --disable mysql80-community
[root@localhost ~]# yum-config-manager --enable mysql57-community

此时查看mysql5.7版本已经被启用了

[root@localhost ~]# yum repolist enabled |grep mysql
mysql-connectors-community/x86_64       MySQL Connectors Community           206
mysql-tools-community/x86_64            MySQL Tools Community                 94
mysql57-community/x86_64                MySQL 5.7 Community Server           624

3.安装MySql并启用

安装Mysql

yum install -y  mysql-community-server    #视网络情况而定,需要等待

查看版本

Linux在线yum方式安装mysql5.7(适用于mysql8.0)

设置开机自启并启动

systemctl start mysqld
systemctl enable mysqld
Linux在线yum方式安装mysql5.7(适用于mysql8.0)

4. 初始化mysql

  • 在 MySQL 服务器初始启动时,如果服务器的数据目录为空,则会发生以下情况:
    •   MySQL 服务器已初始化
    •   在数据目录中生成SSL证书和密钥文件
    •   安装并启用该 validate_password 插件
    •   将创建一个超级用户 帐户’root’@‘localhost’。并会设置超级用户的密码,将其存储在错误日志文件/var/log/mysqld.log中
 grep 'temporary password' /var/log/mysqld.log

我们可以用上述临时密码登陆mysql,但是自从mysql5.7版本之后自带了安全配置向导命令mysql_secure_installation,下面我们将以此方式来进行

  • 运行mysql_secure_installation会执行几个设置:
    • 为root用户设置密码
    • 删除匿名账号
    • 取消root用户远程登录
    • 删除test库和对test库的访问权限
    • 刷新授权表使修改生效
[root@localhost ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:                #设置root密码,需要大小写英文+数字+特殊符号
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y                                         #默认选择是
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.                                        #移除匿名用户


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.                                        #关闭root远程登陆

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
                                                #移除test数据库
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.                                        #重新加载用户权限表

All done!
Linux在线yum方式安装mysql5.7(适用于mysql8.0)
利用上面设置密码登陆

5.远程访问mysql数据库

创建新的MySQL用户账户,用于远程访问MySQL。

  1. MySQL默认占用的端口号为3306。使用过程中需要防火墙放行3306端口。
  2. 创建并配置远程访问MySQL的账号。
    • 依次运行以下命令,并允许远程主机使用该账号访问MySQL。
    • 账号为cnaaa、密码为PASSword123!
      • mysql> create user ‘cnaaa’@’%’ identified by ‘PASSword123!’;
      • mysql> grant all privileges on . to ‘cnaaa’@’%’with grant option;
      • mysql> flush privileges;
  3. 使用cnaaa账号远程登录MySQL。

文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/6489

(0)
郭靖的头像郭靖
上一篇 2022年12月30日 下午4:27
下一篇 2023年1月4日 下午4:54

相关推荐

  • 手把手教你在Centos7.6环境下安装Redis(含详细图文)

    1.Linux安装redis 下载: wget http://download.redis.io/releases/redis-2.8.17.tar.gz 解压源码包 tar xzf redis-2.8.17.tar.gz 解压完成后的目录 redis-2.8.17 安装 执行完make命令后,在redis-2.8.17 的 src目录下会出现编译后的 re…

    2022年6月14日
    51900
  • Sql Server数据库显示中文乱码的解决方案

    .数据库中文乱码原因 1. 一种情况是实际生产环境的电脑并不支持中文语言,但是数据库的数据表里面,有些说明字段需要用中文显示,这个时候就出现了乱码了 2. 另外一种情况是,安装数据库的时候,使用的是默认的编码规则。这个时候如果电脑本身就不支持中文语言。然后数据库表里面录入中文,也会出现乱码。支持中文的电脑,安装使用默认的选项,数据表录入中文,好像没有出现过乱…

    2023年2月18日
    35200
  • count(1)、count(*)与count(列名)的执行区别

    在工作中遇到count(*)、count(1)、count(col) ,可能会让你分不清楚,都是计数,干嘛这么搞这么多东西。 count 作用 COUNT(expression):返回查询的记录总数,expression 参数是一个字段或者 * 号。 测试 MySQL版本:5.7.29 创建一张用户表,并插入一百万条数据,其中gender字段有五十万行是为n…

    2023年1月12日
    40600
  • mysql的主从延迟问题主要原因及解决

    MySQL数据库主从的安装搭建方法 在实际的生产中,为了解决Mysql的单点故障已经提高MySQL的整体服务性能,一般都会采用主从复制。 比如:在复杂的业务系统中,有一句sql执行后导致锁表,并且这条sql的的执行时间有比较长,那么此sql执行的期间导致服务不可用,这样就会严重影响用户的体验度。 主从复制中分为主服务器(master)和从服务器(slave)…

    2022年6月14日
    84000
  • MySQL数据库断电修复(Database page corruption on disk or a failed)

    一、报错信息 启动日志如下: 看日志的大体的意思是数据页的损坏。 二、解决方案 2.1 修改配置  /etc/my.cnf 配置文件修改innodb 启动参数修改 如果innodb_force_recovery = 1不生效,则可尝试2-6几个数字。 然后重启mysql,重启成功。然后使用mysqldump或 pma 导出数据,执行修复操作等。修复完成后,把…

    2023年12月29日
    12700

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信