how to use mysql lock/unlock [duplicate] - mysql

This question already has answers here:
MySQL wait_timeout Variable - GLOBAL vs SESSION
(3 answers)
Differences between SET var = 'abc' and SET GLOBAL var = 'abc'?
(1 answer)
Closed 3 years ago.
I have two questions about MySQL usage:
I installed mysql5.7 by default options.
then I connect to MySQL by MySQL query browser:
1) if I run "SET autocommit='OFF'", then I use "show variables like 'autocommit';" to check the value, but I still get the result:
autocommit='ON'.
Only if I run "SET global autocommit='OFF';" then I can see the value has been changed, why?
2) with autocommit='ON' , I want to lock a table by:
lock tables xxx write
but I can still query this table from another session.
why?

Related

Can I add values with conditions in mySQL [duplicate]

This question already has answers here:
MySQL You are using safe update mode and you tried to update a table without a WHERE
(2 answers)
Closed 2 years ago.
I'm trying to add a numeric value to a column whose "AuthDate" is "06/05/20" and "Time" is "1P -2P".
I ran the following query:
update main
set calls = 2072
where authdate = '06/05/20'
and time = '1P - 2P';
*main = table name
calls = column name
but I get error code 1175 You are using safe update mode
Does anyone know why I get the error?
Your database or session has option sql_safe_updates enabled. Amongst other things, this forbids update that do not have a where clause, or that have a where clause whose columns are not keys (are not indexed). Even if there is an index, but the optimize chooses not to use it, the query is also aborted.
This is more of an option that prevents mistakes from beginners. If you really know what you are doing, you can disable the option at session level:
set sql_safe_updates = 0;
Side note: I am suspicious about condition authdate = '06/05/20':
if autdate is of a date-like datatype, then you should give it a legitimate date string, like: authdate = '2020-06-05' (or '2020-05-06'?)
if it's a string then... consider storing it as a date; storing dates as string is bad practice for many reasons, and should be avoided

Registering new accounts MySql [duplicate]

This question already has answers here:
MySQL #1364 - Field 'column_name' doesn't have a default value - Can't insert into DB [duplicate]
(1 answer)
mysql error 1364 Field doesn't have a default values
(20 answers)
Closed 3 years ago.
I have an online gta san andreas server and have recently changed the game mode, but when a user tries to create a new account to play with these errors appear below:
Blockquote
[13:41:34] [ERROR] ID: 1364 - Error: Field 'Sexo' doesn't have a default value - Callback - OnQueryFinish - Query: INSERT INTO usuarios (username, password,posX,posY,posZ,vida,money,banco,skin,Registro,Email,EMS,Edad) VALUES ('Onion_Games','91752300','1715.5295','-1900.1307','13.5664','100','6000','10000','250','22/09/2019','oniongames#gmail.com',1,23)
how can i fix this?
This error indicates that:
when inserting, you did not provide a value for field Sexo
this column was defined as NOT NULL when the table was created, and no default value was defined
Possible solutions are:
provide the value when inserting
set up a default value in the definition of the table

Getting result set from non-sql query [duplicate]

This question already has an answer here:
How to get Description of MySQL Table in GoLang
(1 answer)
Closed 3 years ago.
How do I retrieve data sets from non-standard MySQL "show" statement using golang? For example, "show tables", "show variables", "show engine innodb status". etc.
I cannot find any information to retrieve the result set from mysql "show" statement in Golang. Using either database/sql package or sqlx package is fine.
Got it! Here is the code. It worked!
var r1, r2, r3 string
row := db.QueryRow("show engine innodb status")
err = row.Scan(&r1, &r2, &r3)

SET mysql variable with list of mails [duplicate]

This question already has answers here:
How to pass a variable to a IN clause?
(4 answers)
Closed 5 years ago.
I need to define a list of variables to use in multiple MySQL queries.
The variable will be a list of mails. I have tried to define it in different ways but it always gives me error in the construction.
SET #listamails='mail1#gmail.com,mail2#gmail.com';
Select * from user WHERE mail IN (#listamails);
Any ideas?
Thank you
You cannot pass in a list to IN using a single variable. The simplest solution in MySQL is find_in_set():
Select u.*
from user u
where find_in_set(mail, #listamails) > 0;
However, this cannot take advantage of an index. For that, you might want to use dynamic SQL.
Try this
SET #listamails='mail1#gmail.com','mail2#gmail.com';
Select * from user WHERE mail IN (#listamails);

Mysql select query to get FIND_IN_SET [duplicate]

This question already has answers here:
MySQL find_in_set with multiple search string
(7 answers)
Closed 9 years ago.
The following query works good.
SELECT FIND_IN_SET('b','a,b,c,d');
// output -> 2
I need to fetch the record having multiple options. Just for an example,
SELECT FIND_IN_SET('b,c','a,b,c,d');
// output -> ??????????
Please how do i get the record with multiple selection option "b,c" in "a,b,c,d".
mysql function find_in_set can search only for one string in a set of strings.
the second its not a string in set of strings
take a look here
edit:
to change the mode
This can be done in two ways...
1- Open your "my.ini" file within the MySQL installation directory, and look for the text "sql-mode".
Find:
Code:
Set the SQL mode to strict sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Replace with:
Code:
Set the SQL mode to strict sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Or
2- You can run an SQL query within your database management tool, such as phpMyAdmin:
Code:
SET ##global.sql_mode= '';