0、查询mysql版本
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.19 |
+-----------+
1 row in set (0.00 sec)
1、vim /etc/my.cnf 加入skip-grant-tables
修改完成 :wq
保存
2、重启MySQL
systemctl restart mysqld
3、免密登录
直接输入:
mysql
4、进入mysql数据库:
use mysql
5、修改密码
mysql> update user set authentication_string = password("123456") where user="root";
Query OK, 2 rows affected, 1 warning (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 1
成功:
[root@pomole init.d]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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>
6、关闭免密
注释skip-grant-tables
7、重启服务器和验证免密是否失效
[root@pomole init.d]# systemctl restart mysqld
[root@pomole init.d]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
有的版本不允许使用弱口令,如果想要取消强口令限制,也有其他办法。