Home >Database >Mysql Tutorial >CentOS6下安装mysql后,重置root密码方法_MySQL

CentOS6下安装mysql后,重置root密码方法_MySQL

WBOY
WBOYOriginal
2016-06-01 13:18:52824browse

CentOS6CentOS

bitsCN.com

本人在CentOS6.4上安装万mysql后,无法通过root进入,因为安装的时候,并没有设置root密码,似乎有个初始随机密码,但是不记得了,太麻烦,直接重置root密码。

使用rpm包安装完mysql后,按照一下步骤重置root密码:

启动mysql:
#/etc/init.d/mysql start


启动成功后查看mysql进程信息,获取mysqld_safe的安装目录(非常关键)
#ps -ef | grep -i mysql
root 3466 1 0 01:45 pts/1 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/BSC.TEST.pid
mysql 3569 3466 16 01:45 pts/1 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/BSC.TEST.err --pid-file=/var/lib/mysql/BSC.TEST.pid
root 3597 3105 0 01:45 pts/1 00:00:00 grep -i mysql

可以看到mysqld_safe的安装位置(上面标蓝色部分):/usr/bin/
接着执行一下命令停止mysql:
/etc/init.d/mysql stop

以安全方式启动mysql:
#/usr/bin/mysqld_safe --skip-grant-tables >/dev/null 2>&1 &

稍等5秒钟,然后执行以下语句:
#/usr/bin/mysql -u root mysql
注意:mysql与mysql_safe目录一样,都是:/usr/bin/下,这个是通过“ps -ef | grep -i mysql”命令得到的。

出现“mysql>”提示符后输入:
mysql> update user set password = Password('root') where User = 'root';
回车后执行(刷新MySQL系统权限相关的表):
mysql> flush privileges;
再执行exit退出:
mysql> exit;

退出后,使用以下命令登陆mysql,试试是否成功:

#mysql -u root -p

按提示输入密码:root

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn