因爲每個系統mysql 的配置文件位置不同,我們只需要修改mysql的配置文件my.cnf即可實現免密登錄
1、修改mysql配置文件
在mysql的配置文件裏面添加skip-grant-tables保存即可
[mysqld]
bind-address = 0.0.0.0
skip-grant-tables #添加此行代碼即可
2、重啓mysql服務
servier mysqld restart
3、進入mysql數據庫
注意:mysql數據庫的user表中沒有password這個字段會報錯,只有authentication_string這個字段,
[root@mysql ~]# mysql
mysql> use mysql;
mysql> update user set password = password("*****") where user='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> update user set authentication_string=password("*****") where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges; # 立即生效
Query OK, 0 rows affected (0.02 sec)