centos安装mysql8.0 (yum安装)

一、yum安装mysql
#下载mysql,安装目录/var/lib/mysql
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
#yum安装
yum localinstall mysql80-community-release-el7-1.noarch.rpm
#更新yum
yum clean all
yum makecache
#创建mysql
groupdel mysql    #删除原有mysql
groupadd mysql
useradd -g mysql mysql
#开始安装mysql
yum module disable mysql
yum install mysql-community-server
#启动mysql
systemctl start mysqld
#查看启动状态
systemctl status mysqld.service
#查看初始化密码,两种方法
cat /var/log/mysqld.log | grep password   
grep "password" /var/log/mysqld.log
二、登录mysql,并进行设置
#登录
mysql -u root -p
#修改密码,密码一定要大小写字母+数字+符号,如:Aa-123456789
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'A123456789a.'; #已验证
#查看完整的初始密码规则
mysql>show variables like 'validate_password';
#配置mysql表

mysql>SHOW DATABASES;
mysql>use mysql;
mysql>show tables;
mysql>select host,user,plugin from user;

#客户端提供MYSQL的环境,但是不支持中文,通过以下命令可以查看mysql的字符集
mysql>show variables like 'character_set%';
#需要把字符集改成UTF-8

#允许任何主机访问数据库
#mysl 8之前
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
#mysql 8之后
mysql>create user root@'%' identified by 'A123456789a.'; grant all privileges on *.* to root@'%' with grant option;
#指定主机
mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@’10.10.50.127IDENTIFIED BY '654321' WITH GRANT OPTION;

# 然后刷新权限
mysql>flush privileges;

#刷新权限
FLUSH PRIVILEGES;
#注意:一定要记得在写sql的时候要在语句完成后加上" ; "
#在操作中,如果没反应重启服务器
shutdown -r now
#配置mysql.cnf,查找mysql --help|grep 'my.cnf'
cd /etc
vim mysql.cnf
default_authentication_plugin = mysql_native_password

mysql> SELECT Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host      | User             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
+-----------+------------------+-----------------------+
#修改验证
update user set plugin='mysql_native_password' where User='root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
# 然后刷新权限
mysql>flush privileges;
#刷新权限
FLUSH PRIVILEGES;
三、远程登录报错解决:2059 - authentication plugin ‘caching_sha2_password
#查看加密方式
mysql> show variables like 'default_authentication_plugin';
+-------------------------------+-----------------------+
| Variable_name                 | Value                 |
+-------------------------------+-----------------------+
| default_authentication_plugin | caching_sha2_password |
+-------------------------------+-----------------------+
# 在Navicat不支持MySQL8.0.19的这种用户登录账户加密方式,所以下面我们要修改root账户的加密方式为【mysql_native_password】
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'A123456789a.';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'A123456789a.';
#查看所有权限,%和root为 mysql_native_password时即可
mysql> select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | mysql_native_password |
+-----------+------------------+-----------------------+


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值