MySql增加使用者、授權、修改密碼等語句
MySql增加使用者、授權、修改密碼等語句
資料庫top_develop
登入資料庫
1:新增使用者
[mysql@lcamdb ~]$ mysql -u root -p
Enter password: *****
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>use mysql
mysql> insert into mysql.user(Host,User,Password,ssl_cipher,x509_issuer,x509_subject) values("localhost","top_hdz",password("top_hdz"),'','','');
Query OK, 1 row affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT host, user, password FROM user WHERE user = "top_hdz";
+-----------+---------+-------------------------------------------+
| host | user | password |
+-----------+---------+-------------------------------------------+
| localhost | top_hdz | *9E2182EFC0FDC01E6EDC9FE113C4158587B31889 |
+-----------+---------+-------------------------------------------+
1 row in set (0.00 sec)
進行登入測試
[mysql@lcamdb mysql]$ mysql -u top_hdz -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 5.6.17 Source distribution
Copyright (c) 2000, 2014, 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> use top_develop
ERROR 1044 (42000): Access denied for user 'top_hdz'@'localhost' to database 'top_develop'
2:進行授權,訪問top_develop 資料庫所有物件的許可權
grant all privileges on top_develop.* to top_hdz@localhost identified by 'top_hdz';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
許可權新增之後:
mysql> use top_develop
ERROR 1044 (42000): Access denied for user 'top_hdz'@'localhost' to database 'top_develop'
mysql> use top_develop
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> exit
Bye
如果想指定部分許可權給一使用者,可以這樣來寫:
mysql>grant select,update on top_develop.*
3.刪除使用者。
@>mysql -u root -p
@>密碼
mysql>Delete FROM user Where User="top_hdz" and Host="localhost";
mysql>flush privileges;
//刪除使用者的資料庫
mysql>drop database top_develop;
4.修改指定使用者密碼。
@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password('新密碼') where User="top_hdz" and Host="localhost";
mysql>flush privileges;
5.列出所有資料庫
mysql>show database;
6.切換資料庫
mysql>use '資料庫名';
7.列出所有表
mysql>show tables;
8.顯示資料表結構
mysql>describe 表名;
9.刪除資料庫和資料表
mysql>drop database 資料庫名;
mysql>drop table 資料表名;
資料庫top_develop
登入資料庫
1:新增使用者
[mysql@lcamdb ~]$ mysql -u root -p
Enter password: *****
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>use mysql
mysql> insert into mysql.user(Host,User,Password,ssl_cipher,x509_issuer,x509_subject) values("localhost","top_hdz",password("top_hdz"),'','','');
Query OK, 1 row affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT host, user, password FROM user WHERE user = "top_hdz";
+-----------+---------+-------------------------------------------+
| host | user | password |
+-----------+---------+-------------------------------------------+
| localhost | top_hdz | *9E2182EFC0FDC01E6EDC9FE113C4158587B31889 |
+-----------+---------+-------------------------------------------+
1 row in set (0.00 sec)
進行登入測試
[mysql@lcamdb mysql]$ mysql -u top_hdz -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 5.6.17 Source distribution
Copyright (c) 2000, 2014, 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> use top_develop
ERROR 1044 (42000): Access denied for user 'top_hdz'@'localhost' to database 'top_develop'
2:進行授權,訪問top_develop 資料庫所有物件的許可權
grant all privileges on top_develop.* to top_hdz@localhost identified by 'top_hdz';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
許可權新增之後:
mysql> use top_develop
ERROR 1044 (42000): Access denied for user 'top_hdz'@'localhost' to database 'top_develop'
mysql> use top_develop
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> exit
Bye
如果想指定部分許可權給一使用者,可以這樣來寫:
mysql>grant select,update on top_develop.*
3.刪除使用者。
@>mysql -u root -p
@>密碼
mysql>Delete FROM user Where User="top_hdz" and Host="localhost";
mysql>flush privileges;
//刪除使用者的資料庫
mysql>drop database top_develop;
4.修改指定使用者密碼。
@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password('新密碼') where User="top_hdz" and Host="localhost";
mysql>flush privileges;
5.列出所有資料庫
mysql>show database;
6.切換資料庫
mysql>use '資料庫名';
7.列出所有表
mysql>show tables;
8.顯示資料表結構
mysql>describe 表名;
9.刪除資料庫和資料表
mysql>drop database 資料庫名;
mysql>drop table 資料表名;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28869493/viewspace-2142548/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼MySql資料庫密碼
- mysql8.0+修改使用者密碼MySql密碼
- mysql如何修改root使用者的密碼MySql密碼
- 授權|取消授權MYSQL資料庫使用者許可權MySql資料庫
- mysql使用者建立、修改、刪除及授權操作的總結MySql
- MySQL建立使用者和授權MySql
- mysql使用者建立與授權MySql
- MySQL新增使用者使用者與授權MySql
- MySQL建立使用者,配置許可權、密碼策略MySql密碼
- 修改 MySQL 登入密碼MySql密碼
- mysql8.0修改密碼MySql密碼
- 修改git使用者密碼Git密碼
- mysql-8.0.16-winx64/Linux修改root使用者密碼MySqlLinux密碼
- sql語句修改欄位型別和增加欄位SQL型別
- 【ASP.NET Core】按使用者等級授權ASP.NET
- 修改docker中Mysql的密碼DockerMySql密碼
- 修改Mysql root密碼的方法MySql密碼
- MySQL-授權使用者管理資料庫MySql資料庫
- Mysql 建立資料庫\新增使用者\使用者授權MySql資料庫
- [譯]使用者賬戶、授權和密碼管理的 12 個最佳實踐密碼
- mysql 8.0.11 資料庫使用者密碼修改詭異的限制MySql資料庫密碼
- mysql 8.0.11 以上版本修改root密碼MySql密碼
- MySQL 8.0之後版本密碼修改MySql密碼
- 實用小技巧! 修改MySQL密碼MySql密碼
- 在Linux中修改MySQL的密碼LinuxMySql密碼
- ubuntu安裝mysql後修改密碼UbuntuMySql密碼
- MySQL修改密碼方法總結YRMySql密碼
- 修改MySQL密碼的四種方法MySql密碼
- MYSQL5.7 ROOT密碼修改教程MySql密碼
- MySQL修改賬號密碼方法大全MySql密碼
- ubuntu系統下mysql重置密碼和修改密碼操作UbuntuMySql密碼
- MySQL8.0 忘記 root 密碼下如何修改密碼MySql密碼
- Flipboard 資料庫未經授權訪問使用者賬號密碼洩露資料庫密碼
- MySQL 修改int型別為bigint SQL語句拼接MySql型別
- 怎麼修改mysql的連線密碼MySql密碼
- mysql建立使用者並且對資料庫授權MySql資料庫
- mysql8.0資料庫新增使用者和授權MySql資料庫
- Ubuntu18.04修改使用者密碼Ubuntu密碼
- Kali Linux 2020.1修改root使用者密碼Linux密碼