[root@mysql01 ~]#vim /etc/my.cnf
[client]
socket=/usr/local/mysql/data/mysql.sock
[mysqld]
skip-grant-tables #添加本行:跳过密码认证
socket=/usr/local/mysql/data/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
port = 3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
max_connections=2048
character-set-server=utf8
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
[root@mysql01 ~]# service mysqld restart
[root@mysql01 ~]# mysql -u root -p
Enter password: #此处直接回车
mysql> use mysql;
authentication_string=password("新的密码") where user="root";
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@mysql01 ~]# service mysqld restart
[root@mysql01 ~]# mysql -u root -p
Enter password: #此处输入修改后的密码