Mysql - Phpmaydmin - Not processing all inputs in SQL Window - mysql

I do have a MySQL Server and administration is done via pypMyAdmin. All works fine since "forever" but now I realized that I am having a problem:
Often I do SQL Updates using the "SQL" Link (Run SQL query/queries on server).
If entering a lot of Statements (like this):
UPDATE table SET column = 'new value A' WHERE id = 1;
UPDATE table SET column = 'new value B' WHERE id = 2;
UPDATE table SET column = 'new value C' WHERE id = 3;
....
UPDATE table SET column = 'new value Z' WHERE id = 100;
I have encountered that only about 40-50 Statements are done - no error messages, nothing seems broken - just not all 100 or more short SQL Statements are fullfilled ...
Did any of you encounter the same or even better:
What can be done to make sure all lines/SQL Statements are processed?

Not much can be done. I've encountered the same thing and am comfortable submitting a few statements at a time via phpMyAdmin, but for anything more than say 20 simple statments I go to my MySQL host and import a file with all my statements like $>mysql -u me -pmypass mydb < file_with_many_statements.sql
There's clearly a limitation that could depend on a number of factors (native to phpMyAdmin, settings in your phpMyAdmin hosts's php/web server/mysql configs, network issues, etc.)

Related

OPENQUERY SQL Server MYSQL UPDATE

I have to work on a linked server. My goal: Update an entire table in mysql server(version:8.0.21) via OPENQUERY in SQL Server(version 13.0.1742.0). I tried this but it generates an error Row cannot be located for updating. Some values may have been changed since it was last read and this one The rowset was using optimistic concurrency and the value of a column has been changed after the containing row was last fetched or resynchronized.
update linkedTable
set
linkedTable.id_parent=unlinkedTable.IdCat1,
linkedTable.code=unlinkedTable.CodeFamilleFAT,
linkedTable.niveau=unlinkedTable.NiveauCategorieFAT,
linkedTable.langue=unlinkedTable.CodeLangueFAT,
linkedTable.nom=unlinkedTable.LibelleCommercialFAT,
linkedTable.descriptionA=unlinkedTable.DescriptifCom1FAT,
linkedTable.vignette=null,
linkedTable.id_categorie=unlinkedTable.id
from openquery(NAMELINKEDSERVER, 'select id_categorie, id_parent, code, niveau, langue, nom, description as descriptionA, vignette from DatabaseMySQL.Table') as linkedTable
inner join DatabaseSQLserver.dbo.Table as unlinkedTable on unlinkedTable.Id = linkedTable.id_categorie
Then I tried this:
update linkedTable
set
linkedTable.id_parent=unlinkedTable.IdCat1,
linkedTable.code=unlinkedTable.CodeFamilleFAT,
linkedTable.niveau=unlinkedTable.NiveauCategorieFAT,
linkedTable.langue=unlinkedTable.CodeLangueFAT,
linkedTable.nom=unlinkedTable.LibelleCommercialFAT,
linkedTable.descriptionA=unlinkedTable.DescriptifCom1FAT,
linkedTable.vignette=null,
linkedTable.id_categorie=unlinkedTable.id
from openquery(NAMELINKEDSERVER, 'select id_categorie, id_parent, code, niveau, langue, nom, description as descriptionA, vignette from DatabaseMySQL.Table') as linkedTable
inner join DatabaseSQLserver.dbo.Table as unlinkedTable on unlinkedTable.Id = linkedTable.id_categorie
where linkedTable.id_categorie = 1
This work but only one row is updated. So I wrote a stored procedure to update each line but it took too much time.
Can someone explain why my first query didn't work (question1) and how I can reduce the time of my stored procedure (question2)?
I use while loop (count the number of id and update each id).
Thank you in advance.
Kind Regards.
I resolve the problem by checking some option on ODBC Driver in MySQL and reading some forum. I check this box.
enter image description here
This option allows to avoid the errors quoted previously. With this option, i can update multiple values without error on join or other request. Thank you Solarflare and "Another guy" (i lost the name) for correcting me (EDIT A POST). Have nice day both.

How do raw query in kohana freamwork

I want make package with list of query.
It is update query like as:
UPDATE table
SET column = XXX
WHERE column = XXX AND column2 = XXX;
UPDATE table
SET column = XXX
WHERE column = XXX AND column2 = XXX;
UPDATE table
SET column = XXX
WHERE column = XXX AND column2 = XXX;
I have these 1000 queries in one package. Now I want make do queries.
I try do it, but unsuccessfully, because every time I get an error like that:
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...
I copy this query and past to phpmyadmin and I do it. These queries work!
I have a variable with prepared queries and I trying to do it in different way.
Database::instance()->query(NULL,$sql);
DB::query(5,$sql)->execute();
DB::query(Database::UPDATE,DB::expr($sql))->execute();
DB::query(Database::UPDATE,$sql)->execute();
but it does not work ;/
Anyone know how do it?
Just call method query from instance of database:
/** #var Database $db */
$db = Database::instance();
$db->query(Database::UPDATE, 'UPDATE table SET column = XXX WHERE column = XXX AND column2 = XXX;');
But if you want execute multiple SQL statements in one query it's impossible out of box. By default Kohana use old mysql API and mysql_query do not support multiple queries in a single call.
It you want use multiple SQL statements i know 3 way:
Some times ago for Kohana i saw module for mysqli support, you can try to find him and modify: add to it new method which will be use http://php.net/manual/en/mysqli.multi-query.php mysqli::multi_query can execute multiple SQL statements in one query.
Or you can switch to using PDO. For this you must make changes in your database config file, according Kohana's documentation, add map for columns in models.
Or create new PDO connection in set up it only for this query (if you don't use transaction it will be more easy, than variant 2).
Also for variant 2 and 3 you must set up some PDO settings: https://stackoverflow.com/a/6461110/419665
P.S. For call database instance by config name:
Database::instance('config_name');

How to update a row in a MySQL database using Ruby's Sequel toolkit?

This should be the simplest thing but for some reason it's eluding me completely.
I have a Sequel connection to a database named DB. It's using the Mysql2 engine if that's important.
I'm trying to update a single record in a table in the database. The short loop I'm using looks like this:
dataset = DB["SELECT post_id, message FROM xf_post WHERE message LIKE '%#{match}%'"]
dataset.each do |row|
new_message = process_message(row[:message])
# HERE IS WHERE I WANT TO UPDATE THE ROW IN THE DATABASE!
end
I've tried:
dataset.where('post_id = ?', row[:post_id]).update(message: new_message)
Which is what the Sequel cheat sheet recommends.
And:
DB["UPDATE xf_post SET message = ? WHERE post_id = ?", new_message, row[:post_id]]
Which should be raw SQL executed by the Sequel connector. Neither throws an error or outputs any error message (I'm using a logger with the Sequel connection). But both calls fail to update the records in the database. The data is unchanged when I query the database after running the code.
How can I make the update call function properly here?
Your problem is you are using a raw SQL dataset, so the where call isn't going to change the SQL, and update is just going to execute the raw SQL. Here's what you want to do:
dataset = DB[:xf_post].select(:post_id, :message).
where(Sequel.like(:message, "%#{match}%"))
That will make the where/update combination work.
Note that your original code has a trivial SQL injection vulnerability if match depends on user input, which this new code avoids. You may want to consider using Dataset#escape_like if you want to escape metacharacters inside match, otherwise if match depends on user input, it's possible for users to use very complex matching syntax that the database may execute slowly or not handle properly.
Note that the reason that
DB["UPDATE xf_post SET message = ? WHERE post_id = ?", new_message, row[:post_id]]
doesn't work is because it only creates a dataset, it doesn't execute it. You can actually call update on that dataset to run the query and return number of affected rows.

BIRT - org.eclipse.birt.data.engine.odaconsumer.OdaDataException: Cannot get the result set metadata

In BIRT, When i try to fetch the records from my localhost, its working fine. But when i try to work with remote connection i am getting error as specified below:
Error :
org.eclipse.birt.data.engine.odaconsumer.OdaDataException: Cannot get the result set metadata.
org.eclipse.birt.report.data.oda.jdbc.JDBCException: SQL statement does not return a ResultSet object.
SQL error #1:Table 'test.TBLUSERS' doesn't exist ... 63 more
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'testbms.TBLUSERS' doesn't exist
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
Note:
Tablenames are automatically changing to capital letters, is that because of it.
Because client server is linux and is it acting with case sensitive.
But it displays column names but not the records. As soon as i click
on finish, i get the error as specified in the below images.
Reference Image:
As you can see in the above image, it has populated the table columns in the second row
Is their any special configurations need to be done for remote connection or am i doing anything wrong?
As you stated, it is probably a case of case-sensitivity:
http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html
Although database and table names are not case sensitive on some
platforms, you should not refer to a given database or table using
different cases within the same statement. The following statement
would not work because it refers to a table both as my_table and as
MY_TABLE: mysql> SELECT * FROM my_table WHERE MY_TABLE.col=1;
If your development box isn't case sensitive then when you change the case of your tablename to match that on production you'll still be able to test. There might also be a way in MySQL using system tables. (See the following query for an example of querying to see if a table exists.):
SELECT count(*)
FROM information_schema.tables
WHERE table_schema = <schema-or-db-name>
AND table_name = <table-or-view-name>
but more realistically, your target database should be passed to your report through a variable that you can check in the scripting of the dataset. Set the "this.query" value to equal the appropriate query based on that variable's value.
E.G.:
if ( params["source_db"].value == "Server=myProductionAddress;Database=myProductionDB;Uid=myUsername;Pwd=myPassword;" )
{
this.query = "SELECT .... prodTableName";
}
else
{
this.query = "SELECT .... devTableName";
}

MySQL error code: 1175 during UPDATE in MySQL Workbench

I'm trying to update the column visited to give it the value 1. I use MySQL workbench, and I'm writing the statement in the SQL editor from inside the workbench. I'm writing the following command:
UPDATE tablename SET columnname=1;
It gives me the following error:
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
....
I followed the instructions, and I unchecked the safe update option from the Edit menu then Preferences then SQL Editor. The same error still appear & I'm not able to update this value. Please, tell me what is wrong?
It looks like your MySql session has the safe-updates option set. This means that you can't update or delete records without specifying a key (ex. primary key) in the where clause.
Try:
SET SQL_SAFE_UPDATES = 0;
Or you can modify your query to follow the rule (use primary key in where clause).
Follow the following steps before executing the UPDATE command:
In MySQL Workbench
Go to Edit --> Preferences
Click "SQL Editor" tab and uncheck "Safe Updates" check box
Query --> Reconnect to Server // logout and then login
Now execute your SQL query
p.s., No need to restart the MySQL daemon!
SET SQL_SAFE_UPDATES = 0;
# your code SQL here
SET SQL_SAFE_UPDATES = 1;
SET SQL_SAFE_UPDATES=0;
UPDATE tablename SET columnname=1;
SET SQL_SAFE_UPDATES=1;
No need to set SQL_SAFE_UPDATES to 0, I would really discourage it to do it that way. SAFE_UPDATES is by default on for a REASON. You can drive a car without safety belts and other things if you know what I mean ;)
Just add in the WHERE clause a KEY-value that matches everything like a primary-key comparing to 0, so instead of writing:
UPDATE customers SET countryCode = 'USA'
WHERE country = 'USA'; -- which gives the error, you just write:
UPDATE customers SET countryCode = 'USA'
WHERE (country = 'USA' AND customerNumber <> 0); -- Because customerNumber is a primary key you got no error 1175 any more.
Now you can be assured every record is (ALWAYS) updated as you expect.
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 Editor and reconnect.
Turn OFF "Safe Update Mode" temporary
SET SQL_SAFE_UPDATES = 0;
UPDATE options SET title= 'kiemvieclam24h' WHERE url = 'http://kiemvieclam24h.net';
SET SQL_SAFE_UPDATES = 1;
Turn OFF "Safe Update Mode" forever
Mysql workbench 8.0:
MySQL Workbench => [ Edit ] => [ Preferences ] -> [ SQL Editor ] -> Uncheck "Safe Updates"
Old version can:
MySQL Workbench => [Edit] => [Preferences] => [SQL Queries]
Preferences...
"Safe Updates"...
Restart server
SET SQL_SAFE_UPDATES=0;
OR
Go to Edit --> Preferences
Click SQL Queries tab and uncheck Safe Updates check box
Query --> Reconnect to Server
Now execute your sql query
If you are in a safe mode, you need to provide id in where clause. So something like this should work!
UPDATE tablename SET columnname=1 where id>0
On WorkBench I resolved it By deactivating the safe update mode:
-Edit -> Preferences -> Sql Editor then uncheck Safe update.
The simplest solution is to define the row limit and execute. This is done for safety purposes.
I found the answer. The problem was that I have to precede the table name with the schema name. i.e, the command should be:
UPDATE schemaname.tablename SET columnname=1;
Thanks all.
In the MySQL Workbech version 6.2 don't exits the PreferenceSQLQueriesoptions.
In this case it's possible use: SET SQL_SAFE_UPDATES=0;
Since the question was answered and had nothing to do with safe updates, this might be the wrong place; I'll post just to add information.
I tried to be a good citizen and modified the query to use a temp table of ids that would get updated:
create temporary table ids ( id int )
select id from prime_table where condition = true;
update prime_table set field1 = '' where id in (select id from ids);
Failure. Modified the update to:
update prime_table set field1 = '' where id <> 0 and id in (select id from ids);
That worked. Well golly -- if I am always adding where key <> 0 to get around the safe update check, or even set SQL_SAFE_UPDATE=0, then I've lost the 'check' on my query. I might as well just turn off the option permanently. I suppose it makes deleting and updating a two step process instead of one.. but if you type fast enough and stop thinking about the key being special but rather as just a nuisance..
I too got the same issue but when I off 'safe updates' in Edit ->
Preferences -> SQL Editor -> Safe Updates, still I use to face the
error as "Error code 1175 disable safe mode"
My solution for this error is just given the primary key to the table if not given and update the column using those primary key value.
Eg: UPDATE [table name] SET Empty_Column = 'Value' WHERE
[primary key column name] = value;
True, this is pointless for the most examples. But finally, I came to the following statement and it works fine:
update tablename set column1 = '' where tablename .id = (select id from tablename2 where tablename2.column2 = 'xyz');
This is for Mac, but must be same for other OS except the location of the preferences.
The error we get when we try an unsafe DELETE operation
On the new window, uncheck the option Safe updates
Then close and reopen the connection. No need to restart the service.
Now we are going to try the DELETE again with successful results.
So what is all about this safe updates? It is not an evil thing. This is what MySql says about it.
Using the --safe-updates Option
For beginners, a useful startup option is --safe-updates (or
--i-am-a-dummy, which has the same effect). It is helpful for cases when you might have issued a DELETE FROM tbl_name statement but
forgotten the WHERE clause. Normally, such a statement deletes all
rows from the table. With --safe-updates, you can delete rows only by
specifying the key values that identify them. This helps prevent
accidents.
When you use the --safe-updates option, mysql issues the following
statement when it connects to the MySQL server:
SET sql_safe_updates=1, sql_select_limit=1000, sql_max_join_size=1000000;
It is safe to turn on this option while you deal with production database. Otherwise, you must be very careful not accidentally deleting important data.
just type SET SQL_SAFE_UPDATES = 0; before the delete or update and set to 1 again
SET SQL_SAFE_UPDATES = 1
If you're having this problem in a stored procedure and you aren't able to use the key in the WHERE clause, you can solve this by declaring a variable that will hold the limit of the rows that should be updated and then use it in the update/delete query.
DELIMITER $
CREATE PROCEDURE myProcedure()
BEGIN
DECLARE the_limit INT;
SELECT COUNT(*) INTO the_limit
FROM my_table
WHERE my_column IS NULL;
UPDATE my_table
SET my_column = true
WHERE my_column IS NULL
LIMIT the_limit;
END$
As stated in previous posts, changing the default settings of the database server will result in undesired modification of existing data due to an incorrect query on the data in a published project. Therefore, to implement such commands as stated in previous posts, it is necessary to run them in a test environment on sample data and then execute them after testing them correctly.
My suggestion is to write a WHERE conditional statement that will loop through all the rows in all conditions if an update should work for all rows in a table. For example, if the table contains an ID value, the condition ID > 0 can be used to select all rows:
/**
* For successful result, "id" column must be "Not Null (NN)" and defined in
* INT data type. In addition, the "id" column in the table must have PK, UQ
* and AI attributes.
*/
UPDATE schema_name.table_name
SET first_column_name = first_value, second_column_name = second_value, ...
WHERE id > 0;
If the table does not contain an id column, the update operation can be run on all rows by checking a column that cannot be null:
/**
* "first_column_name" column must be "Not Null (NN)" for successful result.
*/
UPDATE schema_name.table_name
SET first_column_name = first_value, second_column_name = second_value, ...
WHERE table_name.first_column_name IS NOT NULL;
MySql workbench gave me the same error, after I unchecked safe mode , I then reconnected the server and the update function worked.
Go to Query in the menu bar and reconnect the server
Query Menu -> Reconnect to Server
You can enable and disable safe update option by following commands.
To Disable,
SET SQL_SAFE_UPDATES=0;
or
SET SQL_SAFE_UPDATES=OFF;
To Enable,
SET SQL_SAFE_UPDATES=1;
or
SET SQL_SAFE_UPDATES=ON;
First:
Please make sure you want to update all records in that table because without the where clause it is dangerous to update all records in that table. It's rare time you want to update all records in the table.
most of the time you want to update specific records which should include where cluase if again you want to update all records open MySQL workbench> Edit> Preference>SQL Editor > scroll down at right and uncheck the "Safe Updates(rejects UPDATEs and DELETEs with no restrictions)".
It is for safe updates.
If you uncheck the above said then there are chances that you update all records instead of one record which leads to a database backup restore. there is no rollback.
I've just added COMMIT; in the end
You can enable and disable safe update option by following commands.
SET SQL_SAFE_UPDATES=1;