1. 设置无密码登录
编辑/etc/my.cnf 添加 skip-grant-tables 不实用密码登录MySQL
下边是样例
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# cancel password check
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
2. 登录
由于/etc/my.cnf中设置了取消密码验证,所以此处密码任意
/usr/local/mysql/bin/mysql -u root -p
3.修改密码
# 操作mysql数据库
>>use mysql;
# 修改root密码为123
>>update user set authentication_string=password('123') where user='root';
>>flush privileges;
>>exit;