MYSQL UPDATE date field not working - mysql

Why won't this work:
USE presentations_db; UPDATE presentations_tbl SET `date` = '2012-12-13' WHERE `date` = '2013-12-12'
I have tried everywhere I could and can't find an answer.
date is the field name so used back ticks as required. date is of DATE data type.

I managed to get it to run through the commandline. I clicked on "command line client" and it asked for a password. I then ran the sql statement and got the following result:
mysql> UPDATE `presentations_db`.`presentations_tbl`SET date_ = '2012-12-13' WHERE date_ = '2013-12-12';
Query OK, 16 rows affected (0.06 sec) Rows matched: 16 Changed: 16 Warnings: 0
When I tried to run the same query by simply running mysql though a shell it came up with an error that the db can not be edited by localhost, which is more explanatory than 'Query interrupted'. This seems to be a gripe previously covered in http://bugs.mysql.com/bug.php?id=67766.
It would be nice if somone can tell me what I am doing wrong in workbench gui. I normally do the following when trying to run queries. I click on 'Edit Table Data' and the select the database and tables. It seems like I can view and run select queries but not update queries.

Related

MySQL update returns 0 rows affected while select returns results

select * from t_circle
where status = 0 and author_phone = 13511111111
and id in (
1,
2,
3
)
;
returns 3 rows with status of 0.
But the following update query with same conditions returns 0 rows affected:
udpate t_circle set status = 2
where status = 0 and author_phone = 13511111111
and id in (
1,
2,
3
);
Is there a reason for this? I have tried start transaction and commit, but still 0 rows affected. Other questions' answers suggest to run select first and make sure the rows are changed since if new value == old value, it is considered affected. I have excluded these 2 possibilities.
Note: this issue is found in our production server(Yeah I know I shouldn't but I have to) with InnoDB engine. I could modify the contents in GUI client like DBeaver and click save and the changes take effect, but not with sql statements. I wonder if it has anything to do with my account authorization?
Resolved! It is because I misspelled UPDATE. When I use mysql> in command line, update with 'udpate' just gives Query OK, 0 rows affected. My mysql's version is 5.7
I know that there is something wrong with the user permission of your client
By comparing GUI generated sql queries when I change something in GUI and my own queries. I found out the reason is I misspelled update to udpate. Now I begin to wonder how could mysql not complain about syntax error and just returns with 0 rows affected?
Well, at least now I know what to do when something odd happens.

SQL database command not updating

I am trying to execute this:
UPDATE WORKS_ON
SET Hours = 5.0
WHERE Essn=99988777 AND Pno=10;
and it threw an error,
19:07:29 UPDATE WORKS_ON SET Hours=5.0 WHERE Essn=99988777 AND Pno=10 Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect. 0.000 sec
I did what it asks and reconnected, now there is no error but doesn't do anything
19:36:26 UPDATE WORKS_ON SET Hours= 5.0 WHERE Essn=99988777 AND Pno=10 0 row(s) affected Rows matched: 0 Changed: 0 Warnings: 0 0.000 sec
I want all Hours for people that have Essn=999887777 and Pno=10. Hours will change to 5.0
I hope you have already unchecked safe updates in preferences.
From what you have posted it looks like there are no matching rows where Essn=99988777 and Pnp=10 at the same time.If you can provide sample data and expected results it would be better
First set SQL_SAFE_UPDATES=0, It’s because you try to update a table without a WHERE that uses a KEY column, if you use PRIMARY KEY then it would not create that kind of problem, let's try this way
SET SQL_SAFE_UPDATES=0;
UPDATE WORKS_ON
SET Hours = 5.0
WHERE Essn=99988777 AND Pno=10;
EDIT
you can modify your query to follow the rule (use PRIMARY KEY on WHERE clause), if it doesn't work, then precede the (table name with the schema name) like
UPDATE your_schemaname.WORKS_ON
SET Hours = 5.0
WHERE Essn=99988777 AND Pno=10;

Why is this mySQL UPDATE not making changes?

I know nothing about mySQL. A friend and I are struggling with this tiny bit of code.
Background:
I'm trying to solve an issue I have with character encoding on my WordPress database. My original WordPress database is wordpress, and the modified database is wordpress2 (which exists largely as a copy of the original). I want to select the post_content of a single entry in wordpress, convert it to utf8, and insert it into the corresponding row in wordpress2.
The Script:
update wordpress2.wp_posts wp2
set wp2.post_content = (select convert(wp.post_content using utf8)
from wordpress.wp_posts wp
where wp.ID = wp2.ID )
where wp2.ID = 789;
When run:
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
Why isn't this changing any rows? What do we need to do to make it do so?
Thank you.
The answer, as #zerkms first pointed out in the comments above, was that the values were already identical.

MySQL row_count() function always returning 0

I want to show the result of rows affected after update, insert, or delete in mysql. I have put
DELETE FROM A WHERE ID='1';
SELECT ROW_COUNT();
With the ROW_COUNT the last statement, but the result show me is 0.
If you want to know number of rows affected by delete query in PHPMYADMIN then by running your query it will show you the result see below screenshot :
As #Flash Thunder said PHPmyadmin does not allow multiple queries sent at once
If you want to see the affected rows then you can also write a script using PHP which will exceute you sql query and returns the number of affected rows
Just to be clear.
phpMyAdmin is written in PHP, and PHP does not allow multiple queries sent at once... if you are sending two queries separately, second query is on new connection, so it has no access to previous query information. That's why SELECT ROW_COUNT(); returns 0.
But by default phpMyAdmin returns affected rows count in information after query. It probably uses mysql(i)_affected_rows() function.
FOUND_ROWS() returns number of tables in database when there was no previous query.
mysql> use hunting;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select found_rows();
+--------------+
| found_rows() |
+--------------+
| 24 |
+--------------+
1 row in set (0.00 sec)
mysql> show tables;
(...)
24 rows in set (0.00 sec)

Why does MySQL allow to update a NOT NULL column to NULL?

I'm running MySql in ubuntu 10.10. I created a table called 'employee' having 3 field names empno, name and salary. Inserted few entities. In the middle of the process i want to change salary attribute as 'NOT NULL'. I Alter the table as
ALTER TABLE employee MODIFY salary int(10) NOT NULL;
Query executed. I wanted to test by using command,
UPDATE employee SET salary=NULL;
Query OK, 15 rows affected, 15 warnings (0.06 sec)
Rows matched: 15 Changed: 15 Warnings: 15
also gave warnings " (Code 1048): Column 'salary' cannot be null "(Repeated for every row)
But when i saw my table , All salaries were Zeros('0').
Same queries result in error instead of warning in WINDOWS XP's MySql
I checked in both INNODB and MYISAM engines but same Result.
Please help me to know what happened beside processing.
You must not have SQL_MODE set to strict on you ubuntu installation.
Issue
SET SQL_MODE='STRICT_ALL_TABLES'
or add
SQL_MODE='STRICT_ALL_TABLES'
under [mysqld] to your my.cnf on Ubuntu.
I don't see the problem, you set the column to NOT NULL, (which doesn't allow NULL values) and now it won't let you set it to NULL, which would be the expected behaviour.
The reason you have 0s in your DB is because 0 would be the result of casting NULL to an int.