美文网首页PHP程序员
MySQL如何找到MySQL的安装路径

MySQL如何找到MySQL的安装路径

作者: php转go | 来源:发表于2020-08-26 09:06 被阅读0次

    一般情况下,可以通过Linux的find指令可以找到MySQL的安装路径

    [test@localhost ~]# find / -name mysql -type d
    /etc/selinux/targeted/active/modules/100/mysql
    /etc/selinux/targeted/tmp/modules/100/mysql
    /root/php-7.3.0/travis/ext/mysql
    /var/lib/mysql
    /var/lib/mysql/mysql
    
    

    当只有一个mysql目录时,一下子就能找到
    但是当服务器有多个MySQL的目录时,就不清楚具体是哪一个目录
    这次就直接用SQL语句来找到安装的根目录

     show variables like '%basedir%';
    #或者
    select @@basedir as basePath from dual ;
    

    执行时示例与得到结果

    mysql> show variables like '%basedir%';
    +---------------+----------------------------+
    | Variable_name | Value                      |
    +---------------+----------------------------+
    | basedir       | /rdsdbbin/mysql-5.6.44.R1/ |
    +---------------+----------------------------+
    1 row in set (0.72 sec)
    mysql> select @@basedir as basePath from dual ;
    +----------------------------+
    | basePath                   |
    +----------------------------+
    | /rdsdbbin/mysql-5.6.44.R1/ |
    +----------------------------+
    1 row in set (0.28 sec)
    
    

    查看数据库存放的位置

    select @@datadir as dataPath from dual ;
    #或者
    show variables Like '%datadir%';
    

    示例

    mysql> select @@datadir as dataPath from dual ;
    +-----------------+
    | dataPath        |
    +-----------------+
    | /var/lib/mysql/ |
    +-----------------+
    1 row in set (0.09 sec)
    
    mysql> show variables Like '%datadir%';
    +---------------+-----------------+
    | Variable_name | Value           |
    +---------------+-----------------+
    | datadir       | /var/lib/mysql/ |
    +---------------+-----------------+
    1 row in set (0.08 sec)
    

    拓展

    通过查看进程的方式找到MySQL的安装目录

    [root@VM_0_2_centos ~]# ps -ef | grep mysql
    root     15837     1  0 Mar16 ?        00:00:00 /bin/sh /www/server/mysql/bin/mysqld_safe --datadir=/www/server/data --pid-file=/www/server/data/VM_0_2_centos.pid --sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    mysql    16441 15837  0 Mar16 ?        01:49:49 /www/server/mysql/bin/mysqld --basedir=/www/server/mysql --datadir=/www/server/data --plugin-dir=/www/server/mysql/lib/plugin --user=mysql --sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION --log-error=VM_0_2_centos.err --open-files-limit=65535 --pid-file=/www/server/data/VM_0_2_centos.pid --socket=/tmp/mysql.sock --port=3306
    

    但是在某些服务器执行时,并没有展示路径,是个坑

    相关文章

      网友评论

        本文标题:MySQL如何找到MySQL的安装路径

        本文链接:https://www.haomeiwen.com/subject/ywomjktx.html