当前位置:Gxlcms > 数据库问题 > 配置数据库服务器

配置数据库服务器

时间:2021-07-01 10:21:17 帮助过:27人阅读

3.1 问题

本例要求熟悉MariaDB数据库的简单管理操作,完成下列任务:

  1. <code>将 MariaDB 数据库的管理密码设为 1234567
  2. 新建一个名为 newdb1 的数据库
  3. 删除名为 test 的数据库
  4. 授权数据库用户 zhsan 可从本机访问任何数据库,拥有所有权限,访问密码为 pwd123</code>

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连接数据库

  1. <code>[root@svr7 ~]# mysql -uroot -p1234567
  2. .. ..
  3. MariaDB [(none)]></code>

2)查看现有的数据库列表

  1. <code>MariaDB [(none)]> SHOW DATABASES;
  2. +--------------------+
  3. | Database |
  4. +--------------------+
  5. | information_schema |
  6. | mysql |
  7. | performance_schema |
  8. | test |
  9. +--------------------+
  10. 4 rows in set (0.01 sec)</code>

3)创建名为newdb1的新库

  1. <code>MariaDB [(none)]> CREATE DATABASE newdb1;
  2. Query OK, 1 row affected (0.00 sec)</code>

4)再次查看现有的数据库列表,确认新库newdb1已在列

  1. <code>MariaDB [(none)]> SHOW DATABASES;
  2. +--------------------+
  3. | Database |
  4. +--------------------+
  5. | information_schema |
  6. | mysql |
  7. | newdb1 |
  8. | performance_schema |
  9. | test |
  10. +--------------------+
  11. 5 rows in set (0.00 sec)</code>

步骤三:删除名为 test 的数据库

1)删除库test

  1. <code>MariaDB [(none)]> DROP DATABASE test;
  2. Query OK, 0 rows affected (0.00 sec)</code>

2)查看库列表确认结果

  1. <code>MariaDB [(none)]> SHOW DATABASES;
  2. +--------------------+
  3. | Database |
  4. +--------------------+
  5. | information_schema |
  6. | mysql |
  7. | newdb1 |
  8. | performance_schema |
  9. +--------------------+
  10. 4 rows in set (0.00 sec)</code>

步骤四:授权新的数据库用户 zhsan

1)新建数据库用户zhsan

使新用户zhsan可从本机访问任何数据库,拥有所有权限,访问密码为 pwd123。

  1. <code>MariaDB [(none)]> GRANT all ON *.* TO zhsan@localhost IDENTIFIED BY ‘pwd123‘;
  2. Query OK, 0 rows affected (0.00 sec) </code>

断开数据库连接并退出。

  1. <code>MariaDB [(none)]> quit
  2. Bye
  3. [root@svr7 ~]#</code>

2)以数据库用户zhsan连接本机的数据库系统

  1. <code>[root@svr7 ~]# mysql -uzhsan -ppwd123
  2. .. ..
  3. MariaDB [(none)]>
  4. MariaDB [(none)]> quit
  5. Bye
  6. [root@svr7 ~]# </code>

配置数据库服务器

标签:配置   数据库   服务器   

人气教程排行