一、yum安装mysql
wget https:
yum localinstall mysql80-community-release-el7-1.noarch.rpm
yum clean all
yum makecache
groupdel mysql
groupadd mysql
useradd -g mysql mysql
yum module disable mysql
yum install mysql-community-server
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.127’ IDENTIFIED 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 |
+-----------+------------------+-----------------------+