我有一个 mysql 数据库,数据库名称中有一个点
数据库名称= "abc.domain.com"
我对 linux 命令行的查询是
mysql -u"root" -p"123" -h 0 -e"USE information_schema;select column_name, column_type from information_schema.columns where TABLE_SCHEMA = `abc.domain.com` AND table_name=`bugs`;" | column -t > /tmp/describe
在上面的命令中,我在反引号之间写了数据库名称 `` 它理解为 linux 命令。
在 mysql 中它运行良好。
如何解决这个问题?
最佳答案
试试这个:
/bin/sh -c mysql -u"root" -p"123" -h 0 -e"USE information_schema;select column_name, column_type from information_schema.columns where TABLE_SCHEMA = \\\`abc.domain.com\\\` AND table_name=\\\`bugs\\\`;" | column -t > /tmp/describe
或者
$ export F='USE information_schema;select column_name, column_type from information_schema.columns where TABLE_SCHEMA = `abc.domain.com` AND table_name=`bugs`;'
$ printenv F
USE information_schema;select column_name, column_type from information_schema.columns where TABLE_SCHEMA = `abc.domain.com` AND table_name=`bugs`;
/bin/sh -c mysql -u"root" -p"123" -h 0 -e $F | column -t > /tmp/describe
编辑1:
Access denied for user 'root'@'localhost' (using password: NO)
不建议使用没有密码的root How to Reset the Root Password
关于来自 linux 命令行的 mysql 数据库,数据库名称中带有点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47325689/