a.
首先停止服務/etc/init.d/mysqld stop,在/etc/my.cnf中添加:
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
user=mysql
啟動mysql服務,輸入mysql登陸
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=password ('lixi') where user='root';
Query OK, 3 rows affected (0.02 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
修改完後重新開機mysql然後在以自己修改的密碼登陸就ok了
b.源碼安裝mysql及密碼破解
CentOS release 6.4 (Final)
Kernel \r on an \m
[root@192_168_2_193 ~]# uname -r
2.6.32-358.el6.x86_64
<a href="http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.63.tar.gz" target="_blank">tar xzf mysql-5.1.63.tar.gz ;cd mysql-5.1.63 ;./configure --prefix=/usr/local/mysql --enable-assembler &&make -j8&&make -j8 install</a>
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
/etc/init.d/mysqld restart
設定相關參數及初始化資料庫
useradd mysql
chown -R mysql.mysql /usr/local/mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=./var
--basedir=/usr/local/mysql/
chown -R mysql.mysql var
/usr/local/mysql/bin/mysqld_safe --user=mysql &
/usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables &跳過權限啟動背景
/usr/local/mysql/bin/mysql 登陸 use mysql;update user set password=password('lixi') where user='root';flush privileges;/etc/init.d/mysqld restart
本文轉自 Anonymous123 51CTO部落格,原文連結:http://blog.51cto.com/woshitieren/1672546