Result consisted of more than one row - mysql

I run two simple queries but MySQL displays an error message and do not understand why.
SELECT:
SELECT proy_obs FROM proy WHERE proy_cod = 'C-12-001';
+-------------+
| proy_obs |
+-------------+
| |
+-------------+
1 row in set (0.00 sec)
UPDATE:
UPDATE proy SET proy_obs = 'Test' WHERE proy_cod = 'C-12-001';
ERROR 1172 (42000): Result consisted of more than one row
MySQL version:
mysql Ver 14.14 Distrib 5.1.71, for redhat-linux-gnu (x86_64) using readline 5.1

It looks like you have a trigger(s) defined on your table that is causing the problem.
To check it out run
select trigger_name
from information_schema.triggers
where trigger_schema = schema()
and event_object_table = 'proy';

Related

In MySQL 8.x the string function FROM_BASE64(str) returns result in hexadecimal form instead of a string

I have the following queries -
SELECT "Abc" AS result;
+--------+
| result |
+--------+
| Abc |
+--------+
SELECT TO_BASE64("Abc") AS result;
+--------+
| result |
+--------+
| QWJj |
+--------+
SELECT FROM_BASE64(TO_BASE64("Abc")) AS result;
+----------------+
| result |
+----------------+
| 0x416263 |
+----------------+
--binary-as-hex page in mysql dev site says -
To disable hexadecimal notation, use --skip-binary-as-hex
I tried the following but got error -
mysql> SELECT FROM_BASE64(TO_BASE64("Abc")) --skip-binary-as-hex AS result;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as-hex AS result' at line 1
mysql> SELECT FROM_BASE64(TO_BASE64("Abc") --skip-binary-as-hex) AS result;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as-hex) AS result' at line 1
mysql> SELECT FROM_BASE64(TO_BASE64("Abc" --skip-binary-as-hex)) AS result;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as-hex)) AS result' at line 1
In the same page they have said how can I use the USING utf8mb4 clause to get the result in case of CHAR() and CONVERT() functions but they have not stated anything about FROM_BASE64() function. Nevertheless, I tried it and got error -
SELECT FROM_BASE64(TO_BASE64("Abc") USING utf8mb4) AS result;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING utf8mb4) AS result' at line 1
I tried the UNHEX() function -
ELECT UNHEX(FROM_BASE64(TO_BASE64("Abc"))) AS result;
+----------------+
| result |
+----------------+
| 0x0ABC |
+----------------+
Clearly this is not the desired result as well as all are in capital. Here LCASE() wouldn't work as well as it will turn every word to lower case.
Even, this result is not in string as is evident from -
SELECT SUBSTRING(UNHEX(FROM_BASE64(TO_BASE64("Abc"))) FROM 4) AS result;
+----------------+
| result |
+----------------+
| 0x |
+----------------+
So the only option seems to be to disable -binary-as-hex
But I can't find out a way to do this.
Here as similar question is there in stackoverflow -
'FROM_BASE64' Function Returns Hex Value
But it is on MySQL Version 5.6.14. I am using MySQL Version 8.0.27 -
mysql --version
mysql Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)
So my case is different.
The --skip-binary-as-hex option is to be used as an option to the mysql command when you open that from a shell prompt. It's not an option to be used within SQL syntax. See https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html#option_mysql_binary-as-hex
That said, you can convert binary to strings even if binary-as-hex is enabled:
mysql> SELECT FROM_BASE64(TO_BASE64("Abc")) AS result;
+----------------+
| result |
+----------------+
| 0x416263 |
+----------------+
1 row in set (0.00 sec)
mysql> SELECT CONVERT(FROM_BASE64(TO_BASE64("Abc")) USING utf8mb4) AS result;
+--------+
| result |
+--------+
| Abc |
+--------+
1 row in set (0.00 sec)
You may need to use a different character encoding. Mine is utf8mb4, but yours may be different.

What is the default MySQL database name in XAMPP? [duplicate]

My connection string for MySQL is:
"Server=localhost;User ID=root;Password=123;pooling=yes;charset=utf8;DataBase=.;"
My questions are :
What query should I write to get database names that exist?
What query should I write to get server version?
I have error because of my connection string ends with DataBase=.
What should I write instead of the dot?
SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
SELECT VARIABLE_NAME, VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'VERSION'
Use INFORMATION_SCHEMA as the database.
To get the list of databases, you can use SHOW DATABASES:
SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.01 sec)
To get the version number of your MySQL Server, you can use SELECT VERSION():
SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.1.45 |
+-----------+
1 row in set (0.01 sec)
As for the question about the connection string, you'd want to put a database name instead of the dot, such as Database=test.
show Databases;
Will return you all the registered databases.
And
show variables;
will return a bunch of name value pairs, one of which is the version number.

1064 error in MySQL Command line client when trying to view table but works fine in MySQL Workbench

So i created a database in MySQL Workbench and I am trying to view them on the MySQL Command Line Client because i want to do my queries there instead of the workbench.
Here's whats happening:
mysql> use policestation(crime);
Database changed
mysql> show tables;
+--------------------------------+
| Tables_in_policestation(crime) |
+--------------------------------+
| accused |
| case |
| complainant |
| investigation_officer |
| outcome |
| section_of_law |
+--------------------------------+
6 rows in set (0.04 sec)
mysql> select * from case;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'case' at line 1
The same query works fine in MySQL Workbech. Also it works for all other tables in Command Line Client.
It's b/c Case is a MySQL reserved keyword: https://dev.mysql.com/doc/refman/5.5/en/keywords.html
You'll need to seround reserved keywords with tick marks not quotes.
Example:
SELECT * FROM `case`
Not the same as
SELECT * FROM 'case'
Also here is another helpful link:
Syntax error due to using a reserved word as a table or column name in MySQL

Mysql st_intersects + st_buffer doesn't work

I tried to test if a line is met in some distance from a point. St_distance just gives me what I want. However, I'm curious about st_intersects + st_buffer:
$ mysql --version
mysql Ver 14.14 Distrib 5.6.24, for Linux (x86_64) using EditLine wrapper
mysql> set #l4=st_geomfromtext('LINESTRING(50 50, 52 45)');
mysql> set #g4=st_geomfromtext('POINT(50 49)');
mysql> select st_distance(#l4, #g4);
--------------
select st_distance(#l4, #g4)
--------------
+-----------------------+
| st_distance(#l4, #g4) |
+-----------------------+
| 0.3713906763541037 |
+-----------------------+
1 row in set (0.00 sec)
I would think the point is very close to the line but obviously MySQL disagrees:
mysql> select st_intersects(st_buffer(#g4, 1), #l4);
--------------
select st_intersects(st_buffer(#g4, 1), #l4)
--------------
+---------------------------------------+
| st_intersects(st_buffer(#g4, 1), #l4) |
+---------------------------------------+
| 0 |
+---------------------------------------+
1 row in set (0.00 sec)
Why? Do I miss something?
P.S.
I have tried the commands above in H2GIS and it says it is indeed true!
ST_Intersects should return true in this case.
This appears to be the bug reported here: https://bugs.mysql.com/bug.php?id=71076, and fixed in MySQL 5.7.6, according to the release notes here: http://forums.mysql.com/read.php?3,629183,629183
"This work also corrected issues that [...], and that
ST_Intersects() sometimes incorrectly calculated the
result for intersections of LineString and Polygon."

Show whole text in query result in mysql

I am using mysql (mysql Ver 14.14 Distrib 5.5.34, for debian-linux-gnu (x86_64) using readline 6.2). and i am create a column named external_password
with description external_password | varchar(200) | null =YES | | default =NULL and inserted data.
When I try preform a select operation through command line i got the following result,
mysql> select external_password from login_user WHERE user_name = 'abc#123';
+---------------------------------------------------------+
| external_password |
+---------------------------------------------------------+
| $S$DEjrvXeeDgACuXAN0XkyM6FEPTFcHLcNqV..3SBHxQBpwR9wN7Fd |
+---------------------------------------------------------+
1 row in set (0.00 sec)
But this not showing the full character. between these substring {LcNqV..3SBHxQB} there are lot of other characters are hidden. how can i get the full text by command line??
please help me
NB: i am using using the ubuntu. Also in a situation i can't use phpmyadmin or any other mysql user interfaces.
use ego. this might display more text compared to the table view.
mysql> select external_password from login_user WHERE user_name = 'abc#123'\G
here are other options you can use http://dev.mysql.com/doc/refman/5.1/en/mysql-commands.html