Linux环境——MySQL安装及配置(8.0版本)

时间:2023-03-09 04:13:33
Linux环境——MySQL安装及配置(8.0版本)

虚拟机环境是Linux  Red Hat Enterprlse Linux (64位),本次安装的是Mysql 8.0版本。

由于有经验了,所以又弄了台虚拟机练手,承接上一篇博客(https://www.cnblogs.com/lelelong/p/10767049.html

补充默认密码的截图

可以在文件 【/var/log/mysqld.log】 中获取,如图:

[root@localhost116 mysql]# tail -100f /var/log/mysqld.log
--25T04::.315933Z [System] [MY-] [Server] /usr/sbin/mysqld (mysqld 8.0.) initializing of server in progress as process
--25T04::.323029Z [Note] [MY-] [Server] A temporary password is generated for root@localhost: fu#0YkCp)uv8
--25T04::.526215Z [System] [MY-] [Server] /usr/sbin/mysqld (mysqld 8.0.) initializing of server has completed
--25T04::.986257Z [System] [MY-] [Server] /usr/sbin/mysqld (mysqld 8.0.) starting as process
--25T04::.635553Z [Warning] [MY-] [Server] CA certificate ca.pem is self signed.
--25T04::.667243Z [System] [MY-] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.15' socket: '/var/lib/mysql/mysql.sock' port: MySQL Community Server - GPL.
--25T04::.765178Z [System] [MY-] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port:

这里默认密码就是   fu#0YkCp)uv8

访问:

[root@localhost107 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 8.0. Copyright (c) , , 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>

在【/etc/my.cnf】中修改配置,将default-authentication-plugin=mysql_native_password  去掉前面的#,如下图:

Linux环境——MySQL安装及配置(8.0版本)

重启mysql服务

[root@localhost107 mysql]# service mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定]
[root@localhost107 mysql]#

其他命令:

show variables like '%auth%';    #查看 default_authentication_plugin 的值
show variables like 'default_password_lifetime'; #查看 default_password_lifetime 的值
show variables like '%pass%'; #查看模糊查询pass 属性的值
select user,host,plugin from mysql.user; #查看user表相关字段
set global validate_password_policy=0; #设置 validate_password_policy 全局值为0,可不遵循密码规则
set global validate_password_length=4; #设置 validate_password_length 密码长度最少位数
flush privileges; #修改生效
create user 用户名 identified by '密码'; #新增用户及密码
grant all on *.* to 用户名; #给用户授权所有权限

特别注意:8.0版本中 validate_password.policy /  validate_password.length  最后一个链接符不是下划线_而是点.不然会报错,如下:

mysql> set global validate_password_policy=;
ERROR (HY000): Unknown system variable 'validate_password_policy'

参考博客:https://www.cnblogs.com/leohahah/p/9044904.html