文档课题:mysql实现root用户免密码登录.
数据库:mysql 5.7.42
1、方案一
1.1、修改my.cnf文件
--添加如下配置跳过授权表
skip-grant-tables
1.2、重启mysqld服务
# systemctl stop mysqld
# systemctl start mysqld
1.3、修改密码
# mysql -uroot -p
说明:此时不需要输入密码.
mysql> use mysql
--设置密码
mysql> update user set authentication_string=password('mysql5721_4U'),password_expired='N',password_last_changed=now() where user='root';
--刷新授权表
mysql> flush privileges
1.4、还原my.cnf配置
说明:退出mysql且删除配置文件里的skip-grant-tables,然后重启mysql服务.
2、方案二
[root@leo-mysql5721 ~]# vi .my.cnf
添加如下内容:
[client]
host=localhost
user=root
password=mysql_4U
port=3306
[root@leo-mysql5721 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.21 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




