1. 程式人生 > 資料庫 >mysql修改密碼

mysql修改密碼

mysql修改密碼

mysqladmin -u  root -p password  修改初始密碼
mysql  
忘記root密碼的處理方法
修改配置檔案
vim /etc/my.cnf

新增檔案 skip-grant-tables
跳過密碼驗證
直接 mysql -u root -p  登入進去修改密碼

update mysql.user set authentication_string=password('sha1234567') where user='tom';
修改root密碼
update mysql.user set authentication_string=password('abc123') where user='root';
flush privileges; 重新整理

 grant all on *.* to 'jerry'@'localhost' identified by 'abc123';

 grant all on *.* to 'root'@'%' identified by 'abc123';

-------------------------------------------------------------------------------------

建立普通使用者,及設定許可權
 -------------------------------------------------------------------

建立使用者jerrry ,並提權(如果沒有jerry 使用者,會自動建立)
 grant all on *.* to 'jerry'@'localhost' identified by 'abc123';

檢視檢視使用者許可權的命令是?
SHOW GRANTS FOR 使用者名稱@來源地址
 檢視jerry 的許可權
mysql> show grants for ‘jerry’@‘localhost’;

--------------------------------------------------------------------

 撤銷使用者許可權的命令
REVOKE 許可權列表 ON 資料庫名.表名 FROM 使用者名稱@來源地址

撤銷JERRY使用者的許可權

mysql> revoke all on *.* from 'jerry'@'localhost';
Query OK, 0 rows affected (0.00 sec)

----------------------------------------------------------------------------

Grand :當用戶已存在時,直接提權,當用戶不存在時,先建立使用者再提權

Revoke : 只撤銷許可權,不會刪除使用者
-------------------------------------------------------------------------------------------------------

在mysql 庫下 操作此命令,檢視使用者登入許可權

% 表示在所有終端網段
mysql> select user,host from user;
+-----------+-----------+
| user      | host      |
+-----------+-----------+
| root      | %         |
| mysql.sys | localhost |
| root      | localhost |
+-----------+-----------+
3 rows in set (0.00 sec)

刪除ROOT本地登入許可權

mysql> drop user root@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from user;
+-----------+-----------+
| user      | host      |
+-----------+-----------+
| root      | %         |
| mysql.sys | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)

---------------------------------------------

windows
測試登入
mysql  帶密碼登入

C:\Users\sha>mysql -uroot -h 192.168.100.12  -pabc123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.17 Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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 互動模式登入
C:\Users\sha>mysql -uroot -h 192.168.100.12  -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.17 Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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>