設定密碼

  1. 預設 root 沒密碼,可直接登入。
    [root@kvm3 ~]# mariadb -uroot
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 5
    Server version: 10.5.16-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> quit
    Bye
    
  2. 免密碼登入 mariadb,設定 root 的密碼為 123qwe,並更新權限表。
    [root@kvm3 ~]# mariadb -uroot
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 31
    Server version: 10.5.16-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> alter user 'root'@'localhost' identified by '123qwe';
    Query OK, 0 rows affected (0.067 sec)
    
    MariaDB [(none)]> flush privileges;
    Query OK, 0 rows affected (0.052 sec)
    
    MariaDB [(none)]> quit;
    Bye
    
  3. 再免密碼登入 mariadb,回應存取限制。
    [root@kvm3 ~]# mariadb -uroot
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
    
  4. 以設定的密碼 123qwe 成功登入 mariadb。
    [root@kvm3 ~]# mariadb -uroot -p123qwe
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 33
    Server version: 10.5.16-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> quit
    Bye