mysql 8.0.12 創建新的數據庫、用戶並授權


Mysql安裝成功后,默認的root用戶密碼為空,你可以使用以下命令來創建root用戶的密碼:

[root@host]# mysqladmin -u root password "new_password";

現在你可以通過以下命令來連接到Mysql服務器:

[root@host]# mysql -u root -p
Enter password:*******

注意:在輸入密碼時,密碼是不會顯示了,你正確輸入即可。

 

一、創建數據庫

mysql> create database news character set utf8;
Query OK, 0 rows affected (0.09 sec)

二、創建用戶

mysql> create user 'news'@'39.15.16.14' identified by '123news';
Query OK, 0 rows affected (0.09 sec)

三、授權用戶

mysql> grant all privileges on news.* to 'news'@'39.15.16.14';
Query OK, 0 rows affected (0.10 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

或者 這種方法 :創建並授權用戶,是二和三的合並。

mysql> grant all on asd.* to 'wanghz'@'192.168.1.%' identified by 'w123'
Query OK, 0 rows affected (0.09 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)

四、刪除用戶

查看用戶信息
mysql> select distinct * from (select user.Host,user.User,db.Db,user.Password,user.Drop_priv,user.Grant_priv,user.Alter_priv from db inner JOIN user on db.user=user.user) as it where user='wanghz';
+------+--------+-----------+-------------------------------------------+-----------+------------+------------+
| Host | User   | Db        | Password                                  | Drop_priv | Grant_priv | Alter_priv |
+------+--------+-----------+-------------------------------------------+-----------+------------+------------+
| %    | wanghz | asd | *D98C88AFF81F2B8C5A0930313CD1250C6D81672E | N         | N          | N          |
+------+--------+-----------+-------------------------------------------+-----------+------------+------------+
1 row in set (0.00 sec)

mysql> select * from user where user='wanghz'\G;
*************************** 1. row ***************************
                  Host: %
                  User: wanghz
              Password: *D98C88AFF81F2B8C5A0930313CD1250C6D81672E
           Select_priv: N
           Insert_priv: N
           Update_priv: N
           Delete_priv: N
           Create_priv: N
             Drop_priv: N
           Reload_priv: N
         Shutdown_priv: N
          Process_priv: N
             File_priv: N
            Grant_priv: N
       References_priv: N
            Index_priv: N
            Alter_priv: N
          Show_db_priv: N
            Super_priv: N
 Create_tmp_table_priv: N
      Lock_tables_priv: N
          Execute_priv: N
       Repl_slave_priv: N
      Repl_client_priv: N
      Create_view_priv: N
        Show_view_priv: N
   Create_routine_priv: N
    Alter_routine_priv: N
      Create_user_priv: N
            Event_priv: N
          Trigger_priv: N
Create_tablespace_priv: N
              ssl_type: 
            ssl_cipher: 
           x509_issuer: 
          x509_subject: 
         max_questions: 0
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin: mysql_native_password
 authentication_string: 
      password_expired: N
1 row in set (0.00 sec)

ERROR: 
No query specified

mysql> select * from db where user='wanghz'\G;
*************************** 1. row ***************************
                 Host: %
                   Db: asd
                 User: wanghz
          Select_priv: Y
          Insert_priv: Y
          Update_priv: Y
          Delete_priv: Y
          Create_priv: Y
            Drop_priv: Y
           Grant_priv: N
      References_priv: Y
           Index_priv: Y
           Alter_priv: Y
Create_tmp_table_priv: Y
     Lock_tables_priv: Y
     Create_view_priv: Y
       Show_view_priv: Y
  Create_routine_priv: Y
   Alter_routine_priv: Y
         Execute_priv: Y
           Event_priv: Y
         Trigger_priv: Y
1 row in set (0.00 sec)

ERROR: 
No query specified

mysql> 

 刪除用戶

mysql> drop user 'wanghz'@'%';
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM