Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过命令行mysql访问数据库文件?_Mysql_Sql_Command Line Interface - Fatal编程技术网

如何通过命令行mysql访问数据库文件?

如何通过命令行mysql访问数据库文件?,mysql,sql,command-line-interface,Mysql,Sql,Command Line Interface,我第一次安装mysql,用CreateDatabaseFoo创建了一个数据库; 我想我已经找到了mysql存储数据库的位置(/var/lib/mysql)。当我尝试cd到foo目录时,我的权限被拒绝。当我尝试sudo时,什么都没有发生 ls-l的输出 -rw-rw----. 1 mysql mysql 16384 Feb 21 17:44 aria_log.00000001 -rw-rw----. 1 mysql mysql 52 Feb 21 17:44 aria_log_c

我第一次安装mysql,用CreateDatabaseFoo创建了一个数据库; 我想我已经找到了mysql存储数据库的位置(/var/lib/mysql)。当我尝试cd到foo目录时,我的权限被拒绝。当我尝试sudo时,什么都没有发生

ls-l的输出

-rw-rw----. 1 mysql mysql    16384 Feb 21 17:44 aria_log.00000001
-rw-rw----. 1 mysql mysql       52 Feb 21 17:44 aria_log_control
drwx------. 2 mysql mysql     4096 Mar  1 22:08 foo
-rw-rw----. 1 mysql mysql 18874368 Feb 21 17:44 ibdata1
-rw-rw----. 1 mysql mysql  5242880 Mar  1 16:05 ib_logfile0
-rw-rw----. 1 mysql mysql  5242880 Feb 21 17:34 ib_logfile1
drwx------. 2 mysql mysql     4096 Feb 21 17:34 mysql
srwxrwxrwx. 1 mysql mysql        0 Mar  1 16:05 mysql.sock
drwx------. 2 mysql mysql     4096 Feb 21 17:34 performance_schema

我知道您打算在命令行上通过该应用程序查看数据库和其他内容,但我很想知道为什么我是root用户时无法查看foo目录。

您无法查看foo目录,因为有以下权限:

owner - mysql - read, write, execute
group - mysql - no access
other - no access

首先使用从命令提示符连接到mysql

[root@host]# mysql -u root -p
Enter password:******
现在使用

mysql> USE DB_Name
可以使用belo命令创建数据库列表

mysql> SHOW DATABASES;
要获取目录详细信息,可以使用

mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name = "dir_name"

我以为root可以访问所有东西。如果不是的话,我可以浏览目录然后访问它吗?@user3247608“我以为root可以访问所有东西”我也这么认为。但权限似乎是最可能的解释。请尝试chmod o+rx。因为如果您选择root,mysql将无法读取数据库。