Linux下mysql的root密碼丟失重置

2021-07-24 23:36:49 字數 3374 閱讀 9020

[root@12c ~]# service mysqld stop

停止 mysqld:                                              [確定]

方法一,直接改配置檔案修改/etc/my.cnf 增加skip-grant-tables引數啟動如下。5.7版本下使用root 還需要j加入explicit_defaults_for_timestamp=true

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

skip-grant-tables

#explicit_defaults_for_timestamp=true

這種方法不推薦,修改完後需要改回來。

方法二,啟動時用命令啟動,記得保留這個視窗

[root@12c ~]# /etc/init.d/mysqld start --skip-grant-tables

正在啟動 mysqld: [確定]

重啟動乙個命令視窗,為了區別,這裡注意使用者已經不是root了

[oracle@12c ~]$ mysql -uroot 

welcome to the mysql monitor. commands end with ; or \g.

your mysql connection id is 1

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> show databases;

+--------------------+

| database |

+--------------------+

| information_schema |

| mysql |

| test |

| zebra |

+--------------------+

4 rows in set (0.00 sec)

修改密碼發兩種方式

方式一5.6:

mysql> update mysql.user set password=password('mysql') where user='root';

query ok, 0 rows affected (0.00 sec)

rows matched: 3 changed: 0 warnings: 0

5.7版本

mysql> update mysql.user set authentication_string=password('mysql') where user='root';

query ok, 1 row affected, 1 warning (0.03 sec)

rows matched: 1 changed: 1 warnings: 1

方式二:

mysql> set password for root@localhost=password('mysql');

error 1290 (hy000): the mysql server is running with the --skip-grant-tables option so it cannot execute this statement

第二種方式在此時是不能修改密碼的。

mysql> flush privileges;

query ok, 0 rows affected (0.01 sec)

[root@12c ~]# service mysqld stop

停止 mysqld: [確定]

[root@12c ~]# service mysqld start

正在啟動 mysqld: [確定]

[root@12c ~]# mysql -uroot -p

enter password:

welcome to the mysql monitor. commands end with ; or \g.

your mysql connection id is 2

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> show databases;

+--------------------+

| database |

+--------------------+

| information_schema |

| mysql |

| test |

| zebra |

+--------------------+

4 rows in set (0.00 sec)

mysql>

5.7使用sql修改密碼

mysql> alter user 'root'@'localhost' identified by 'youpassword';

修改完畢。

linux下啟動與修改mysql的root密碼

環境fedora25 使用yum安裝完成mysql社群版版本後,通過命令 myslq u root p登陸資料庫,提示1045 錯誤,因為密碼不正確。沒辦法,只能修改配置檔案的方法來解決這個問題,該解決方法適用忘記密碼的情況 1 停止mysql服務 sudo service mysql stop 2...

ubuntu下獲得linux命令的root許可權

安裝完ubuntu,預設是普通使用者許可權。習慣了windwos裡面的管理員許可權的使用,不用root許可權感覺不爽。改個檔案很麻煩。但是ubuntu中root沒法登入。應該是沒有設定password。在終端中輸入 sudo passwd root enter new unix password 在...

windows下重置mysql5的root密碼

1 殺死mysqld程序。2 如果你丟失或忘記root密碼,你可以用 skip grant tables重啟mysqld來更改密碼。此段文字引述自mysql 5.1手冊 cmd下 執行 mysqld skip grant tables 3 mysql use mysql database chang...