MYSQL Unexpected error message with lock table - mysql

I did a read lock with my table 'Client', after i did an update in my table 'Client' just to see the error message.
So here's what I did:
mysql> LOCK TABLES Client READ;
Query OK, 0 rows affected (0.00 sec)
mysql> UPDATE Client SET pays = 'Suisse' WHERE id = 4;
I expected the error message: ERROR 1100(HY000): Table 'Client' was locked with a READ lock and can't be updated
But i have this message: ERROR 1100 (HY000): Table 'adoption' was not locked with LOCK TABLES
'adoption' is another table in my database !
I hope you will help me, thank you

Related

Re: MySQL 8.0 Command Line Client Error 1205

MySQL 8.0 Command Line Client is giving me a timeout error and I have restarting the transaction by typing "start transaction" another time. Keep in mind that I have another command line open with the table CIA_DATA.new_table and it is also being updated with the same changes. (I am doing this to follow a tutorial.) Here is the script:
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
mysql> update CIA_DATA.new_table set c1 = 2 where c1 = 1;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
Updated code for help in Answers Comments:
mysql> set autocommit=0;
Query OK, 0 rows affected (0.00 sec)
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
mysql> drop table CIA_DATA.new_table;
ERROR 1051 (42S02): Unknown table 'cia_data.new_table'
mysql> create table CIA_DATA.new_table ( c1 int primary key);
Query OK, 0 rows affected (0.08 sec)
mysql> insert into CIA_DATA.new_table values (1);
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.05 sec)
mysql> select * from CIA_DATA.new_table;
+----+
| c1 |
+----+
| 1 |
+----+
1 row in set (0.00 sec)
mysql> update CIA_DATA.new_table set c1 = 2 where c1 = 1;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> close transaction
-> \c
mysql> close transaction;
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 'close transaction' at line 1
mysql> --innodb-lock-wait-timeout=#
-> \c
mysql> --innodb-lock-wait-timeout=#;
->
Thanks,
thecoolgeek
What happen ony your computer:
One transaction locks the table and you didn't release the lock by endind the transaction.
you start a new tansaction and it encounters a lockesd table and waits for the release
As the first transaction and the lock wasn't released, the secnd goes into to timeout.
Locks are in the best case difficult. and sometimes it takes hours or days to solve them.
so close the tranaction as fast as you can, so that the timeout not happen or increase the timeout https://dev.mysql.com/doc/refman/8.0/en/innodb-parameters.html#sysvar_innodb_lock_wait_timeout

ERROR 1030 (HY000): Got error 168 from storage engine

Had a drive crash and recovered my mysql databases from backup. One table didn't make it and I deleted it and its associated files. (InnoDB table.) The table name was "filescan" and there are now no files in the data directory with that root name.
I am able to create and delete other table names, but not "filescan". When I try that, I get an error.
mysql> create table deleteme (id int);
Query OK, 0 rows affected (0.20 sec)
mysql> create table filescan(id int);
ERROR 1030 (HY000): Got error 168 from storage engine
mysql> drop table deleteme
-> ;
Query OK, 0 rows affected (0.03 sec)
mysql> drop table filescan;
ERROR 1051 (42S02): Unknown table 'db1.filescan'
mysql> create table filescan(id int);
ERROR 1030 (HY000): Got error 168 from storage engine
mysql>
Other answers on Stack Exchange and elsewhere seem to indicate this happens when there's a shortage of disk space. I have 130GB+ free and am able to create other tables - just not one named "filescan". I thought it might be a permissions issue, so I checked the permissions of the other files and the enclosing /data folder to ensure I have access.
Any insights?

Not locking tables but am getting error "General error: 1100 Table 'entities' was not locked with LOCK TABLES"

I am trying to run a simple INSERT query, but am receiving an error stating:
General error: 1100 Table 'entities' was not locked with LOCK TABLES
I have not used an implicit LOCK TABLES before the query.
Doing a SHOW FULL PROCESSLIST just previous to the query yeilds:
Id User Host db Command Time State Info
646 my_user my-win-8:4018 db_name Query 0 SHOW FULL PROCESSLIST
The query I am running is:
INSERT INTO entities (type, user_id, created, creator, updated, updater)
VALUE ('some-type', NULL, '2013-07-02 01:30:18', '3', '2014-08-28 23:45:44', '2');

Mysql 1820 error when create procedure

I faced one issue when use mysql to create procedures.
I used "root#localhost" to create the procedure. the command executed successfully.
After that I remove procedure A and want to use "root#127.0.0.1" to create A and then faced the error: 1820 - You must SET PASSWORD before executing this statement.
Actually I have set the password for that, but still error.
And other procedure used "root#127.0.0.1" are all successfully without any error. The issue only faced on A.
As I know this error usually found on create DB. but this time... :(
Anybody can help me? Thanks very much!!!
Right from the manual:
After an account's password has been expired, all operations performed
in subsequent connections to the server using the account result in an
error until the user issues a SET PASSWORD statement to establish a
new account password:
mysql> SELECT 1;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> SET PASSWORD = PASSWORD('new_password');
Query OK, 0 rows affected (0.01 sec)
mysql> SELECT 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
Finally the issue was resolved with below statement:
++++++++++++++++++++++++++++++++++
SET PASSWORD FOR 'some_user'#'some_host' = PASSWORD('newpwd');
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How to Test Select for Update in MySQL

I am performing SELECT ... FOR UPDATE or row level locking with InnoDB tables.
My intention is to only one request can read the same row. So if two users make request for the same data as the same time. Only one of them get data, who fires the query first.
But How can i test that locking is placed or not. as I am testing it by retrieving the same data at same time and both users getting the data.
Note: My tables are InnoDB, My query executes in transaction, my query as below:
SELECT * FROM table_name WHERE cond FOR UPDATE;
Any other thing I have to check for this to make work?
open 2 mysql client session.
on session 1:
mysql> start transaction;
mysql> SELECT * FROM table_name WHERE cond FOR UPDATE;
... (result here) ...
1 row in set (0.00 sec)
on session 2:
mysql> start transaction;
mysql> SELECT * FROM table_name WHERE cond FOR UPDATE;
... (no result yet, will wait for the lock to be released) ...
back to session 1, to update selected record (and release the lock):
mysql> UPDATE table_name SET something WHERE cond;
mysql> commit;
back to session 2:
1) either showing lock timeout error
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
2) or showing result
... (result here) ...
1 row in set (0.00 sec)
3) or showing no result (because corresponding record has been modified, so specified condition was not met)
Empty set (0.00 sec)
You can use own lock mechanizm with lock_by column.
UPDATE table_name SET locked_by=#{proccess_id} WHERE cond and locked_by IS NULL
Now in your program you will get count of affected rows:
if(affected_rows==0)
return 'rows locked'
else
//do your staff with locked_by=#{process_id} rows
With this mechanism you can control locked rows and locking processes. You can also add in UPDATE statement locked_at=NOW() to get more info about locked row.
Don't forget to add some index on locked_by column.
Here is MySQL docs about working with locks.
Before update you can put lock, releasing it after. In another transaction you can check lock using it unique name. Strategy for naming you can choose yourself.