Mysql:BCLinux安装Mysql 5.7.34

闲来无事,下载了个BCLinux的镜像,装了一台虚拟机玩一下。BCLinux是基于Centos 6的,所以命令和我们使用得较多的Centos 7有所不同,下面记录一下如何在BCLinux系统中安装MySQL 5.7.43。

  • 下载rpm包,安装yum源
[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el6-3.noarch.rpm --no-check-certificate
[root@localhost ~]# ls
anaconda-ks.cfg  Documents  install.log         Music                                       Pictures  Templates
Desktop          Downloads  install.log.syslog  mysql80-community-release-el6-3.noarch.rpm  Public    Videos
[root@localhost ~]# rpm -ivh mysql80-community-release-el6-3.noarch.rpm
warning: mysql80-community-release-el6-3.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql80-community-relea########################################### [100%]
[root@localhost ~]# ls /etc/yum.repos.d/
BCLinux-Base.repo  BCLinux-Source.repo  BigCloud.repo  mysql-community.repo  mysql-community-source.repo

根据上面的结果可以看出,mysql的源已经成功,但此时运行 yum provides mysql-server 命令会发现,提供的mysql是8.0版本的,并不是我们想要的5.7系列版本,需要执行以下命令,开关yum源提供的版本。

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

此时再执行命令,就会看到5.7系列版本的MySQL了。

  • 安装MySQL
[root@localhost ~]# yum -y install mysql-community-server-5.7.34-1.el6.x86_64
  • 启动MySQL
[root@localhost ~]# service mysqld status
mysqld is stopped
[root@localhost ~]# service mysqld start
Initializing MySQL database:                               [FAILED]

直接启动MySQL失败,具体原因没有直接显示,需要我们去日志查看。(如果习惯编译安装的同学,可能一下子不知道去哪个目录找日志文件,data目录等,建议可以去/etc/init.d/mysqld这个文件里面找,里面都写得清清楚楚。)

[root@localhost log]# vim /var/log/mysqld.log
2021-06-05T08:04:07.178159Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-06-05T08:04:07.354085Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-06-05T08:04:07.406184Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-06-05T08:04:07.471971Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9a23f96c-c5d4-11eb-8801-000c29a872b6.
2021-06-05T08:04:07.473719Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-06-05T08:04:07.476115Z 0 [ERROR] Could not generate RSA private key required for X509 certificate.
2021-06-05T08:04:07.476148Z 0 [ERROR] Aborting

可以看到,启动失败是由于 **Could not generate RSA private key required for X509 certificate.**导致的。原来在mysql 5.7.6以后增强了安全加密连接 ,但在安装时没有进行初始化。mysql在<mysql_home>/bin下提供了一个mysql_ssl_rsa_setup脚本,需要在安装mysql,初始化后执行该脚本才可以。

# 由于刚刚已经初始化失败一次了,所以需要删除数据目录下的文件,才能重新操作。
[root@localhost log]# rm -rf /var/lib/mysql/*  
[root@localhost log]# mysqld --initialize --user=mysql
[root@localhost log]# mysql_ssl_rsa_setup
# 执行完命令后,可以在数据目录下看到各种key
  • 再次启动MySQL(使用初始密码登录,并重设密码)
[root@localhost log]# service mysqld start
Starting mysqld:                                           [  OK  ]
# 启动成功,在日志文件获取初始密码

在这里插入图片描述

[root@localhost log]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.34

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
(修改密码过于简单的话,可能会不符合密码要求,可以通过设置全局变量,使MySQL接受简单的密码,这里就不展开了。)

以上就是BCLinux安装MySQL5.7.34的具体过程,有点小坑,但问题不大,EOF.

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐