Linux – Adminer 輕量級的資料庫管理介面

Loading

之前都是使用 phpMyAdmin 當作 Mysql(MariaDB) web 管理介面,但同事抱怨太複雜了,找了一下有沒有所謂的 MySQL (MariaDB) Lite 輕量級的管理介面,如下.

phpliteadmin – https://www.phpliteadmin.org/
phpminiadmin – http://phpminiadmin.sourceforge.net/
SQL Buddy – http://sqlbuddy.com/

最後選了 Adminer 操作很精簡而且有中文介面
Adminer – https://www.adminer.org/

測試環境為 CentOS7 x86_64 (虛擬機),Adminer 版本為 4.6.3 .
環境需求

  • 支援的資料庫系統 MySQL, MariaDB, PostgreSQL, SQLite, MS SQL, Oracle, SimpleDB, Elasticsearch, MongoDB
  • Supports PHP 5 and 7 with enabled sessions
  • 支援中文介面

資料庫 MaraiDB

從 CentOS 7 開始的 Database 都換成了 MariaDB (與 MySQL 資料庫是相容的)

[root@localhost ~]# yum update
[root@localhost ~]# yum install -y mariadb mariadb-server mariadb-devel

檢查一下 MariaDB 的服務狀態.

[root@localhost ~]# systemctl enable mariadb
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]$ systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2017-07-21 11:30:32 CST; 2s ago
  Process: 5733 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 5705 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 5732 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─5732 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─5890 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql -...

設定一下 MariaDB

[root@localhost ~]$ mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

剛剛就已經設定了 MariaDB root 密碼.登入看看.

[root@localhost ~]$ mysql -u root -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)

MariaDB [(none)]> exit;
Bye

資料庫的安裝就告一段落了,後面需要安裝 PHPMyAdmin 但在這之前需要啟動 web server (Apache).

Apache (Httpd)

使用 Apache 為 Web server , 如果要採用 Nginx 設定可以參考.

[root@localhost ~]$ yum install -y httpd
[root@localhost ~]$ systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]$ systemctl start httpd
[root@localhost ~]$ systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2017-07-21 12:03:23 CST; 5s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 6418 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
           ├─6418 /usr/sbin/httpd -DFOREGROUND
           ├─6419 /usr/sbin/httpd -DFOREGROUND
           ├─6420 /usr/sbin/httpd -DFOREGROUND
           ├─6421 /usr/sbin/httpd -DFOREGROUND
           ├─6422 /usr/sbin/httpd -DFOREGROUND
           └─6423 /usr/sbin/httpd -DFOREGROUND


如果連不上請先確一下 Firewall 的狀態.

[root@localhost ~]$ systemctl stop firewalld

PHP

phpMyAdmin 主要透過 PHP 的程式語言架構出來的,而 PHP 是一種直譯式的程式語言,用於網頁的撰寫,不同於靜態式的 HTML 它可以依據使用者的需求來呈現不同的網頁內容.

[root@benjr ~]# yum install -y php php-pear php-mysql php-mbstring

順便試一下 PHP 功能運作是否正常.你可以用自己喜歡的編輯器來鍵入下面的內容.

[root@benjr ~]# vi /var/www/html/phpinfo.php
<?php
phpinfo();
?>
[root@localhost ~]$ systemctl restart httpd
[root@localhost ~]$ systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2017-07-21 14:54:28 CST; 1s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 7072 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 7078 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
           ├─7078 /usr/sbin/httpd -DFOREGROUND
           ├─7080 /usr/sbin/httpd -DFOREGROUND
           ├─7081 /usr/sbin/httpd -DFOREGROUND
           ├─7082 /usr/sbin/httpd -DFOREGROUND
           ├─7083 /usr/sbin/httpd -DFOREGROUND
           └─7084 /usr/sbin/httpd -DFOREGROUND

/var/www/html 是 Apache 預設的目錄,你可以修改 /etc/httpd/conf/httpd.conf 修改 DocumentRoot .
這是 PHP 的格式,開啟你的網頁連上你 http://localhost/phpinfo.php ,如果一切運作正常那你會看到和下面一樣的網頁.

Adminer

[root@localhost ~]# cd /var/www/html
[root@localhost html]# wget https://github.com/vrana/adminer/releases/download/v4.6.3/adminer-4.6.3.php
[root@localhost html]# mv adminer-4.6.3.php adminer.php

直接透過 web – http://http://192.168.95.156/adminer.php 就可以進行操作.

沒有解決問題,試試搜尋本站其他內容

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料