centos8使用yum源安装mysql8

Mysql8已经发布有一段时间了,虽然我不太喜欢这个玩意(我是mariadb的忠实用户)但是,架不住客户喜欢。

人就是喜欢mysql,mariadb是啥人不知道。

这里大概记录一下使用yum源安装mysql8的一个记录。

1 :为yum配置mysql8.0的源

vi /etc/yum.repos.d/mysql-community-server.repo
复制代码

内容:

# Enable to use MySQL 8.0
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
复制代码

2 :安装命令:

yum install mysql-server
复制代码

3 :启动命令:

service mysqld start
systemctl start mysqld
复制代码

4 :链接数据库

Mysql安装成功之后,会生成初始密码在日志文件中。或者密码直接是空。

这个具体要参照你的mysql日志文件:

我的日志文件所在地:/var/log/mysql/mysqld.log

扫描二维码关注公众号,回复: 14271338 查看本文章

也有一些同学的日志所在目录是/var/log/mysqld.log

2020-09-26T02:27:21.581631Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2020-09-26T02:27:25.063785Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.21) starting as process 2043
复制代码

上边是我安装mysql8的时候的日志,明确告诉我密码是空。

因此这里直接登录就可以了。

mysql -uroot -p
复制代码

5 :没有找到初始密码的情况

假如你安装的mysql有初始密码,并且你还没有找到你初始密码是什么。不要急,有办法。

找到你的mysql配置文件my.cnf,使用命令

[root@iZuf60ynur81p6k0ysvtneZ /]# whereis my.cnf
my: /etc/my.cnf
复制代码

在当前文件下的[mysqld]下添加skip-grant-tables:免密登录

修改后的文件如下:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
skip-grant-tables
复制代码

重启mysql:

systemctl restart mysqld
复制代码

使用mysql命令登录,刚刚修改的配置文件就是免密登录。

[root@iZuf60ynur81p6k0ysvtneZ /]# mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 13
Server version: 8.0.21 Source distribution
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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>
复制代码

然后使用命令修改root用户的密码:

ALTER USER 
'root'
@
'localhost'
 IDENTIFIED BY 
'12345678'
;
复制代码

可能会报错:

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cann
复制代码

修改方法其实很简单:

运行

flush privileges;
复制代码

执行成功之后,在执行

ALTER USER 
'root'
@
'localhost'
 IDENTIFIED BY 
'12345678'
;
复制代码

命令,即成功。

剩下的数据库配置操作,请参考我之前的文章《Centos7.6配置lnmp》里边有详细的介绍。

有好的建议,请在下方输入你的评论。

欢迎访问个人博客 guanchao.site

猜你喜欢

转载自juejin.im/post/7108893345203617806