1.停止mysql
[root@localhost ~]# /etc/init.d/mysqld stop
2.往配置檔案新增skip_grant_tables引數
[root@localhost ~]# sed -i '/[mysqld]/ a \skip_grant_tables' /etc/my.cnf
3.啟動資料庫
[root@localhost ~]# /etc/init.d/mysqld start
4.修改root密碼,新密碼為111111
[root@localhost ~]# password=$(mysql -e "select password('111111')" | grep -v pass)
[root@localhost ~]# mysql -e "update mysql.user set password='$' from where user='root' and host='localhost';"
5.刪除配置檔案的skip_grant_tables引數
[root@localhost ~]# sed -i '/skip_grant_tables/d' /etc/my.cnf
6.重啟資料庫
[root@localhost ~]# /etc/init.d/mysqld restart
[root@localhost ~]# mysql -uroot -p111111
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 3
server version: 5.1.73 source distribution
oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.
type 'help;' or '\h' for help. type '\c' to clear the current input statement.
mysql>
至此,mysql資料庫的root密碼重置成功;
MySQL修改root密碼
整理了以下四種在mysql中修改root密碼的方法,可能對大家有所幫助 方法1 用set password命令 mysql u root mysql set password for root localhost password newpass 特別注意 此處的password關鍵字是對後面 ne...
mysql修改root密碼
修改mysql初始化密碼 連線mysql mysql u root p123456 enter password設定密碼 set password for root localhost password 123456 刪除mysql密碼校驗 預設不能使用簡單密碼 mysql set global v...
mysql修改root密碼
忘記mysql的root密碼的情況下,重置root密碼!system centos mysql version 5.0 5.5 1.停掉mysql service mysqld stop 2.配置檔案 etc my.cnf中 mysqld 下 新增 skip grant tables 3.啟動mys...