yum安装MySQL 5.7.17

在服务器上安装MySQL可以有两种方式,第一种是在官网上下载对应的压缩包,随后进行解压自己配置,第二种是使用yum安装。第一种方式可以一步一步的配置,对整个安装流程能够熟悉,但是安装时间就相对比较长;而第二种方式的安装时间相对更快,并且省略了中间一系列的配置环境,通过敲命令行的方式就能将MySQL安装好。

一、前言

  • 服务器环境是CentOS 7版本
  • 由于生产系统中的MySQL版本为5.7.17,接下来就以该版本为例进行yum安装。

二、do it

  • 1、下载源
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
  • 2、安装源
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
  • 3、直接安装
yum install mysql-server
  • 4、数据库初始化与启动
mysqld --initialize
mysqld --user=root

初始化完毕之后,root账号其实就已经建好了,这个时候已经有一个随机的默认密码生成了,我们首先需要先找到这个默认密码。
在/var/log/mysqld.log的数据库日志目录下,我们可以使用cat 或者 vim 命令打开看一下,

cat /var/log/mysqld.log

找到关键词“A temporary password”的那一行就能够找到初始默认密码了,下面我贴出一小段日志内容

2019-10-18T11:47:56.314161Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-18T11:47:57.228532Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-10-18T11:47:57.343278Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-10-18T11:47:57.403404Z 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: 20cde219-f19d-11e9-aa1f-00163e120909.
2019-10-18T11:47:57.405247Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-10-18T11:47:58.261839Z 0 [Warning] CA certificate ca.pem is self signed.
2019-10-18T11:47:58.370152Z 1 [Note] A temporary password is generated for root@localhost: mDujj#Vfh9+e
2019-10-18T11:48:08.546110Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-18T11:48:08.547190Z 0 [Note] mysqld (mysqld 5.7.28) starting as process 21629 ...
2019-10-18T11:48:08.549703Z 0 [Note] InnoDB: PUNCH HOLE support available
2019-10-18T11:48:08.549724Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-10-18T11:48:08.549728Z 0 [Note] InnoDB: Uses event mutexes
2019-10-18T11:48:08.549734Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2019-10-18T11:48:08.549737Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-10-18T11:48:08.549740Z 0 [Note] InnoDB: Using Linux native AIO
2019-10-18T11:48:08.549970Z 0 [Note] InnoDB: Number of pools: 1
2019-10-18T11:48:08.550062Z 0 [Note] InnoDB: Using CPU crc32 instructions

可以看到第七行中,这里的初始密码为:mDujj#Vfh9+e

  • 5、修改密码
mysqladmin -uroot -p password

先输入旧密码,然后输入两遍新密码,这个时候密码就修改成功了。

三、总结

熟练使用yum安装开发环境能够极大地提升效率。


参考资料:

发布了58 篇原创文章 · 获赞 91 · 访问量 34万+

猜你喜欢

转载自blog.csdn.net/imVainiycos/article/details/102635805
今日推荐