centos7安装mysql8

下载和准备

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
yum仓库中多了两项
yum clean all
yum makecache
这个命令可以看到哪个是启用的

yum会默认安装启用的最新版本。
想要修改,可以编辑/etc/yum.repos.d/mysql-community.repo


修改enable的值来选择要安装的版本

执行安装:

yum install mysql-community-server

修改默认安装路径

默认是安装在/var/lib/mysql的。 可以改为其他路径,比如/mnt/mysql8/:

vi /etc/my.cnf
[mysqld]
datadir=/mnt/mysql8
socket=/mnt/mysql8/mysql.sock

log-error=/mnt/mysql8/mysqld.log
pid-file=/mnt/mysql8/mysqld.pid

lower-case-table-names=1

启动

systemctl start mysqld

这一步会自动初始化数据库,在/mnt/mysql8下创建系统数据库:


初始

初始化以后,有一个初始化的密码,可以在log中找到:

[root@localhost mysql8]# cat mysqld.log |grep pass
2020-01-10T06:24:01.322045Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 0alTmIprge,C

然后登录,需要加上参数-h127.0.0.1 (因为我装了docker。docker里也有mysql)

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

Copyright (c) 2000, 2019, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> 

首次登录必须修改密码。
三联改密法:前两个是简化密码复杂度策略限制的。

mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.01 sec)

mysql> set global validate_password.length=6;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER root@localhost IDENTIFIED BY '123asd';
Query OK, 0 rows affected (0.05 sec)

配置远程登录

三联配置远程登录:

mysql> create user 'root'@'%' identified by '123asd'
    -> ;
Query OK, 0 rows affected (0.01 sec)

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123asd';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;

大功告成!

navicat连接成功
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。