标签: mysqli

从联合查询中获取表名?

这是我的查询

SELECT Id, productName, Largeimagepath, Discount, Price, Image FROM tablename1 where Active =1 
union 
SELECT Id, productName, Largeimagepath, Discount, Price, Image FROM tablename2 where Active =1
union  
SELECT Id, productName, Largeimagepath, Discount, Price, Image FROM tablename3 where Active =1
Run Code Online (Sandbox Code Playgroud)

它工作正常。

现在我想productName在将来获取各自的表名。

  1. 那么我怎样才能取到它呢?

我试过AS..像这样:

SELECT Id, productName, Largeimagepath, Discount, Price, Image
FROM tablename3 AS tablename
where Active = 1;
Run Code Online (Sandbox Code Playgroud)

但没有得到输出。

  1. 我应该如何更正查询并提高查询性能?

mysql performance union mysqli query-performance

10
推荐指数
1
解决办法
4万
查看次数

无法将 MySQL 中的 root 访问权限更改为 %

这是一个新的 MySQL 服务器安装。我创建了我的 root 密码作为设置的一部分(在 Centos 6.4 上)。

当我通过终端连接到服务器时,我可以连接到 MySQL 并使用我的 root 密码发出命令。

选择当前用户;

给我:

+----------------+
| current_user   |
+----------------+
| root@localhost |
+----------------+
Run Code Online (Sandbox Code Playgroud)

如果我做:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxxxxx' WITH GRANT OPTION
Run Code Online (Sandbox Code Playgroud)

我得到:

Query OK, 0 rows affected (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时:

SHOW GRANTS;
Run Code Online (Sandbox Code Playgroud)

这是我得到的:

+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*fdfgdgdggfggfgfg' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)

除了 root@localhost 之外,我不应该看到 root@% 的另一行吗?

我遇到的真正问题是我无法从本地主机外部连接到 …

mysql mysqli

6
推荐指数
1
解决办法
8679
查看次数

标签 统计

mysql ×2

mysqli ×2

performance ×1

query-performance ×1

union ×1