1、首先停止mysql服務進程:
service mysql stop
2、編輯mysql的配置文件my.cnf
vim /etc/my.cnf
3、找到 [mysqld]這個模塊:
在最後面添加一段代碼
skip-grant-tables ##忽略mysql權限問題,直接登錄
4、然後保存 :wq!退出
啓動mysql服務:service mysqld start
5、然後修改密碼
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql> update user set password=password("123456") where user="root";##更新密碼
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
Query OK, 0 rows affected (0.00 sec)
6、 用root登錄
root 56407 1 0 17:50 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/web1.pid
mysql 56533 56407 0 17:50 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/web1.err --pid-file=/data/mysql/web1.pid
root 56560 1737 0 17:55 pts/0 00:00:00 grep mysql
[root@web1 ~]# killall mysqld ##刪除mysql現有進程
[root@web1 ~]# ps -ef |grep mysql
root 56566 1737 0 17:56 pts/0 00:00:00 grep mysql
[root@web1 ~]# service mysqld start ##重新啓動mysql服務
Starting MySQL. SUCCESS!
[root@web1 ~]# mysql -uroot -p ##使用新密碼登錄
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.34 Source distribution
affiliates. Other names may be trademarks of their respective
owners.
7、把剛剛添加的跳過驗證信息刪除,對安全有很大影響