标签: phpmyadmin

  • phpMyAdmin管理MySQL用户

    通过命令行管理MySQL用户不是很方便,

    尤其是变更用户密码和授权的操作,

    需要输入较为复杂的命令,

    如果在机器上部署了phpMyAdmin的话,

    就可以很方便快捷地通过图形界面来操作。

    例如新增用户,删除用户,修改用户密码,数据库授权等。

    参考视频:

    https://www.bilibili.com/video/bv1CK4y177Zr

     

  • phpMyAdmin连接MySQL配置SSL证书

    视频演示:https://www.bilibili.com/video/BV1oy4y1b7yR/

    phpMyAdmin连接 localhost上的MySQL Server是通过unix socket通信的。

    phpMyAdmin连接远程MySQL服务器,如果期望加密通信数据,此时通过配置SSL来实现。

    以Ubuntu为例,MySQL 安装后默认是开启SSL的,在数据目录/var/lib/mysql下通常会有以下文件

    ca.pem

    client-cert.pem

    client-key.pem

    只需要把这3个文件复制到phpMyAdmin所在的服务器上,然后修改phpMyAdmin SSL配置即可。

    切到 phpMyAdmin 部署的根目录,复制文件libraries/config.default.php里面有关ssl的选项到根目录下的config.inc.php中。

    也就是说,在根目录文件config.inc.php中添加下面的配置

    如果根目录没有config.inc.php,应该复制config.sample.inc.php为config.inc.php

    /**
    * Use SSL for connecting to MySQL server?
    *
    * @global boolean $cfg['Servers'][$i]['ssl']
    */
    $cfg['Servers'][$i]['ssl'] = true;
    
    /**
    * Path to the key file when using SSL for connecting to the MySQL server
    *
    * @global string $cfg['Servers'][$i]['ssl_key']
    */
    $cfg['Servers'][$i]['ssl_key'] = 'path/to/client-key.pem';
    
    /**
    * Path to the cert file when using SSL for connecting to the MySQL server
    *
    * @global string $cfg['Servers'][$i]['ssl_cert']
    */
    $cfg['Servers'][$i]['ssl_cert'] = 'path/to/client-cert.pem';
    
    /**
    * Path to the CA file when using SSL for connecting to the MySQL server
    *
    * @global string $cfg['Servers'][$i]['ssl_ca']
    */
    $cfg['Servers'][$i]['ssl_ca'] = 'path/to/ca.pem';
    
    /**
    * Directory containing trusted SSL CA certificates in PEM format
    *
    * @global string $cfg['Servers'][$i]['ssl_ca_path']
    */
    $cfg['Servers'][$i]['ssl_ca_path'] = 'path/to/';
    
    /**
    * List of allowable ciphers for SSL connections to the MySQL server
    *
    * @global string $cfg['Servers'][$i]['ssl_ciphers']
    */
    $cfg['Servers'][$i]['ssl_ciphers'] = null;
    
    /**
    * MySQL 5.6 or later triggers the mysqlnd driver in PHP to validate the
    * peer_name of the SSL certifcate
    * For most self-signed certificates this is a problem. Setting this to false
    * will disable the check and allow the connection (PHP 5.6.16 or later)
    *
    * @link https://bugs.php.net/68344
    * @global string $cfg['Servers'][$i]['ssl_verify']
    */
    $cfg['Servers'][$i]['ssl_verify'] = true;

    配置中的路径为上述三个证书相关文件的实际路径。

    此时,需要确认MySQL是否允许远程连接,

    MySQL配置文件路径 /etc/mysql/mysql.conf.d/mysqld.cnf

    bind-address = 127.0.0.1

    表示只允许本地连接,应该在行首加#注释此行,

    再次,确认MySQL服务器是否允许入站端口3306 ,

    此时应该就可以安全的连接MySQL了。

     

  • phpMyAdmin免输入密码登录

    通过将MySQL的用户名和密码存储在 phpMyAdmin 的配置文件中,

    就可以快捷登录 phpMyAdmin

    免除输入密码的步骤,

    当然最好是部署在内网,

    否则将存在很大安全隐患。

    配置步骤

    1> 复制 config.sample.inc.php 为 config.inc.php

    2> 修改代码示例:

    /**
     * Second server
     */
    $i++;
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'config';
    /* Server parameters */
    $cfg['Servers'][$i]['host'] = 'localhost';
    $cfg['Servers'][$i]['user'] = '';
    $cfg['Servers'][$i]['password'] = '';
    $cfg['Servers'][$i]['compress'] = false;
    $cfg['Servers'][$i]['AllowNoPassword'] = false;

    其中 auth_type 由原来的 cookie 修改为 config

    第9行和10行增加了 user 和 password 的配置

    将用户名和密码写入代码中

    在登陆界面选择服务器后点击执行

    无需填写用户名和密码就可以登录 phpMyAdmin 了

  • phpMyAdmin连接远程服务器配置

    phpMyAdmin登陆界面默认的MySQL服务器只有localhost

    如果想连接其他服务器上的MySQL

    此时只需要在config.inc.php中增加配置就可以了

    首先复制文件 config.sample.inc.php 为 config.inc.php

    然后找到下面的代码片段

     

    /**
     * First server
     */
    $i++;
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    /* Server parameters */
    $cfg['Servers'][$i]['host'] = 'localhost';
    $cfg['Servers'][$i]['compress'] = false;
    $cfg['Servers'][$i]['AllowNoPassword'] = false;

    复制为

    /**
     * Second server
     */
    $i++;
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    /* Server parameters */
    $cfg['Servers'][$i]['host'] = '192.168.1.11';
    $cfg['Servers'][$i]['compress'] = false;
    $cfg['Servers'][$i]['AllowNoPassword'] = false;

     

    注意第8行,新增加的数据库服务器地址为 192.168.1.11

    这样在登录界面就可以看到新增加的服务器了。

    操作视频

    https://www.bilibili.com/video/BV1Ji4y177xc/

  • 基于Ubuntu 20.04 部署phpMyAdmin

    phpMyAdmin是一套优秀的基于WEB的MySQL数据库管理系统, 当需要编写SQL语言和数据库交互时,可以通过phpMyAdmin来替代完成工作,减少错误发生,提高生产效率。

    phpMyAdmin自身使用PHP语言开发,所以部署依赖PHP WEB环境,以下视频示范在全新的Ubuntu 20.04系统上部署PHP7.4/MySQL/Nginx/phpMyAdmin的过程。

    视频地址:

    https://www.bilibili.com/video/BV1Qk4y1B7jB/

    下面是操作执行命令的步骤:

    修改root 密码
    sudo passwd root
    
    切换到root用户
    su root
    
    apt update
    apt install nginx
    apt install mysql-server
    
    mysql
    修改root@localhost的密码
    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'sqlpwd345';
    刷新权限
    flush privileges;
    quit
    
    apt install php7.4
    apt install php7.4-fpm
    apt install php7.4-curl
    apt install php7.4-mysql
    wget https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-all-languages.zip
    apt install unzip
    unzip phpMyAdmin-5.0.2-all-languages.zip
    让nginx支持PHP脚本处理
    vim /etc/nginx/sites-available/default
    service php7.4-fpm start
    service nginx start
    service mysql start