天天看點

配置資料庫伺服器

3.1 問題

本例要求熟悉MariaDB資料庫的簡單管理操作,完成下列任務:

将 MariaDB 資料庫的管理密碼設為 1234567
建立一個名為 newdb1 的資料庫
删除名為 test 的資料庫
授權資料庫使用者 zhsan 可從本機通路任何資料庫,擁有所有權限,通路密碼為 pwd123           

3.2 步驟

實作此案例需要按照如下步驟進行。

步驟一:将 MariaDB 資料庫的管理密碼設為 1234567

1)設定管理密碼

由于預設的資料庫管理者root的密碼為空,是以在第一次設定新密碼時,舊密碼無需指定。

[root@svr7 ~]# mysqladmin -uroot password '1234567'

[root@svr7 ~]#

2)驗證管理密碼

以剛剛設定的管理密碼連接配接本機的資料庫服務。

[root@svr7 ~]# mysql -uroot -p1234567

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 3

Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> //以新密碼成功登入

MariaDB [(none)]> quit //斷開資料庫連接配接并退出

Bye

[root@svr7 ~]#

步驟二:建立一個名為 newdb1 的資料庫

1)以管理者root連接配接資料庫

[root@svr7 ~]# mysql  -uroot  -p1234567
.. ..
MariaDB [(none)]>           

2)檢視現有的資料庫清單

MariaDB [(none)]> SHOW  DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)           

3)建立名為newdb1的新庫

MariaDB [(none)]> CREATE  DATABASE  newdb1;
Query OK, 1 row affected (0.00 sec)           

4)再次檢視現有的資料庫清單,确認新庫newdb1已在列

MariaDB [(none)]> SHOW  DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| newdb1             |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)           

步驟三:删除名為 test 的資料庫

1)删除庫test

MariaDB [(none)]> DROP  DATABASE  test;
Query OK, 0 rows affected (0.00 sec)           

2)檢視庫清單确認結果

MariaDB [(none)]> SHOW  DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| newdb1             |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)           

步驟四:授權新的資料庫使用者 zhsan

1)建立資料庫使用者zhsan

MariaDB [(none)]> GRANT  all  ON  *.*  TO  zhsan@localhost  IDENTIFIED  BY  'pwd123'; 
Query OK, 0 rows affected (0.00 sec)            
MariaDB [(none)]> quit
Bye
[root@svr7 ~]#           
[root@svr7 ~]# mysql  -uzhsan  -ppwd123 
.. ..
MariaDB [(none)]> 
MariaDB [(none)]> quit
Bye
[root@svr7 ~]#