In my project, a table has around 13 million rows and approximately 43 Gb of size. I tried to delete the first 1000 records using laravel delete method.But the execution takes more time and trow exception for me. The exception is
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction (SQL: delete from `demo_table` where `datetime` <= 2020-06-31 00:00:00 order by `id` asc limit 1000)
at r/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
you need to try add additional or change mysql configuration my.ini in Windows or my.cnf in Linux or Mac bellow [mysqld]
[mysqld]
wait_timeout=NumberValue
interactive_timeout = NumberValue
the value in seconds.
after you change it, you need to restart mysql services
You can handle it with nextToken or you can Use Queue for running thread in background
Related
I have the following mysql pattern that I'm using:
try:
print ('111111')
self.cursor.execute(sql, values)
print ('222222') # print to see how long timeouts are taking...
except Exception as error:
# Most likely a deadlock, retry if NumAttemps <= MaxAttempts
logger.exception(error)
...
In another mysql client, to simulate a deadlock, I am doing something like this:
begin;
select * from records where id='10.5240-D5CF-3' for update;
This works, in that it will grab a deadlock and the mysql code will go into the except block, usually with the error:
pymysql.err.InternalError: (1205, 'Lock wait timeout exceeded; try restarting transaction')
Is there a way to specify how long the cursor will wait before it raises the timeout error / or before it 'gives up' if there is a lock? Are both handled by innodb_lock_wait_timeout, or are there multiple settings for this?
Somehow most of my php artisan commands report an error:
C:\Projects\bapestore>php artisan migrate
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = bapestore and table_name = migrations and table_type = 'BASE TABLE')
at C:\Projects\bapestore\vendor\laravel\framework\src\Illuminate\Database\Connection.php:669
665| // If an exception occurs when attempting to run a query, we'll format the error
666| // message to include the bindings with SQL, which will make this exception a
667| // lot more helpful to the developer instead of just the database's errors.
668| catch (Exception $e) {
> 669| throw new QueryException(
670| $query, $this->prepareBindings($bindings), $e
671| );
672| }
673|
1 C:\Projects\bapestore\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDOException::("could not find driver")
2 C:\Projects\bapestore\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct()
I just installed PHP7, Laravel, MAMP, MySQL Workbench locally on my Windows 10 to be able to practice more at home. (Lord, has that been an odyssee..) And now I am trying to connect my database, but the tutorial I follow uses a Mac OS.. so I can't follow the instructions there.
Can anyone understand that error?
You are most likely missing a PHP extension. If you are able to locate your php.ini file, search for extension=mysqli or extension=pdo_mysql extensions. You may need to un-commment them to enable the extensions.
Type in your terminal
php --ini
This command will tell the current path of your php.ini configuration file.
Uncoment the following lines in that file.
extension=php_pdo.dll
extension=php_pdo_mysql.dll
I'm using MySQL server (5.6) database extensively through its .NET connector (6.8.3). All tables are created with MyISAM engine for performance reasons. I have only one process with one thread accessing the DB sequentially, so there is no need for transactions and concurrency.
Please note: this is unlikely to be a timeout configuration issue, because my query is trivial. I did read all timeout related questions (links below). Of course, I may be wrong, but saying just "increase the net_write_timeout parameter" without explaining why exactly it can be relevant here is not an answer.
Some of my tables are created dynamically during program execution so I'm using create on first use idiom, with the following method to check whether the table exists:
private bool TableExists(Space baseSpace, Space extendedSpace)
{
var tableName = GenerateTableName(baseSpace, extendedSpace);
var sqlConnection = this.connectionPool.Take();
this.existsCommand.Connection = sqlConnection;
this.existsCommand.Parameters["#tableName"].Value = tableName.Trim('`');
var result = existsCommand.ExecuteScalar() as long?;
this.connectionPool.Putback(sqlConnection);
return result == 1;
}
The query inside the existsCommand is as follows (broken into two lines here for readability):
SELECT COUNT(*) FROM information_schema.tables
WHERE table_schema = 'my_schema' AND table_name = #tableName
The value of this.existsCommand.Parameters["#tableName"].Value variable contains the correct name of the table, that already exists in this case ("sample_matches_A_to_A_x").
The this.connectionPool.Take() method returns the first MySqlConnection object from my collection of available connections that meets the following predicate:
private bool IsAvailable(MySqlConnection connection)
{
return connection != null
&& connection.State == System.Data.ConnectionState.Open;
}
Usually this works correctly, for a number of hours and then suddenly an exception occurs on this line:
var result = existsCommand.ExecuteScalar() as long?;
With the following contents:
Fatal error encountered during command execution
Stack trace:
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar()
at implementation.SampleMatchesMySqlTable.TableExists(Space baseSpace, Space extendedSpace) in C:...\SampleMatchesMySqlTable.cs:line 168
Inner exception:
Unable to write data to the transport connection: Software caused connection abort.
Inner exception:
Software caused connection abort.
with ErrorCode equal to 10053 and SocketErrorCode being System.Net.Sockets.SocketError.ConnectionAborted
Stack trace of the innermost exception:
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
I've reviewed the following possible duplicates and unfortunately they don't seem relevant here, except one:
SHOW TABLES encountered Fatal error encountered during command execution
Unfortunately, it doesn't provide enough information to decide whether it is an exact duplicate nor it's answered.
There relate to timeout problems. My query is small, returns only one integer, and searches for a table in a meta-table containing something like 20 other tables.
Fatal error encountered during command execution. in C# when i use Insert Into
https://stackoverflow.com/questions/7895178/fatal-error-in-mysql
MySQL Exception - Fatal Error Encountered During Data Read
Fatal error encountered during data read
Fatal error causing timeout -mysql
ADO.Net Entity framework, Fatal error encountered during data read
Different error regarding reading the resultset:
Fatal error encountered during command execution
Syntax errors and connection string issues:
Mysql Fatal error encountered during command execution
fatal error encountered during execution... during update
Fatal error encountered during command execution
fatal error encountered during command execution during update
fatal error encountered during command execution c# mysql
Fatal error encountered during command execution with a mySQL INSERT
I have Fatal error encountered during command execution
MySql exception was unhandled - Fatal error encountered during command execution
https://stackoverflow.com/questions/24098561/mysql-fatal-error-encountered-during-command-execution-in-c-sharp
Fatal Error Encounter During Command Execution MySQL VB
"Fatal error encountered during command execution." mysql-connector .net
"Fatal error encountered during command execution."
C#, MySQL - fatal error encountered during command execution- Checked other solutions, something I am Missing
Creating a view:
"fatal error encountered during command execution" when trying to add a view from MySQL DB
Reading CSV files:
Fatal error encountered during command execution while importing from csv to mysql
MySQL fatal error encountered during command execution - looping through all csv files in folder for load data local infile
I ended up modifying the IsAvailable method as follows:
private bool IsAvailable(MySqlConnection connection)
{
var result = false;
try
{
if (connection != null)
{
result = connection.Ping();
}
}
catch (Exception e)
{
Console.WriteLine("Ping exception: " + e.Message);
}
return result && connection.State == System.Data.ConnectionState.Open;
}
The .Ping call seems to be better in verifying connection's state then its properties, although it's very poorly documented. From some other sources I've read in the meantime:
an alternative is to run a simple query like SELECT 1 FROM DUAL instead of calling Ping.
Also, there seems that sometimes a DataReader, even though it was disposed (everything is implemented with the using statement), is still attached to the connection for some brief period of time. Because of this I've modified the condition to this:
if (connection != null && connection.State == ConnectionState.Open)
The State property has the Executing value as long as a DataReader is attached to it, so additionally verifying if it's Open at the beginning works fine here.
I have this error in my JBoss AS7 logs, and afterwards all database actions have errors like:
ISPN000136: Execution error: java.lang.IllegalStateException:
Transaction TransactionImple < ac, BasicAction:
0:ffff0a400e22:2251d537:519c37fa:35d4 status: ActionStatus.ABORTED >
is not in a valid state to be invoking cache operations on.
HHH000327: Error performing load command :
org.hibernate.cache.CacheException: java.lang.IllegalStateException:
Transaction TransactionImple < ac, BasicAction:
0:ffff0a400e22:2251d537:519c37fa:35d4 status: ActionStatus.ABORTED >
is not in a valid state to be invoking cache operations on.
org.hibernate.cache.CacheException: java.lang.IllegalStateException:
Transaction TransactionImple < ac, BasicAction:
0:ffff0a400e22:2251d537:519c37fa:35d4 status: ActionStatus.ABORTED >
is not in a valid state to be invoking cache operations on.
SQL Error: 0, SQLState: null
javax.resource.ResourceException: IJ000460: Error checking for a
transaction
In this case it appears that a mysqldump of the database was the cause. I think it exhausted the connections accepted by the MySQL server, which caused AS7 to drop its database connection, which caused the errors above.
I have used the --single-transaction mysqldump option and updating the max_connections setting on MySQL to solve the issue.
http://mwibbels.blogspot.com.au/2010/12/mysql-mysqldump-and-dropping-database.html is a good explanation.
I have a connection to a data base and every time there is a problem connecting I get this error.
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server on '205.178.146.104' (4)' in /data/18/2/77/115/2566441/user/2813515/htdocs/ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Abstract.php:129
Stack trace:
#0 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('mysql:dbname=si...', 'xxx', 'xxx', Array)
#1 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect()
#2 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Abstract.php(459): Zend_Db_Adapter_Pdo_Mysql->_connect()
#3 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('DESCRIBE `user`', Array)
#4 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Mysq in .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Abstract.php on line 144
The thing is that the database user and password are visible on the page in the error message. Is there a way that I can prevent PHP from showing that info? Or is this happening because I am set up a a developing instead of production?
It is a combination of both. In development, your showing your errors. Which is the primary reason your seeing that.
However, you can catch the exception by testing the connection before the query. Allowing you to handle your own connection failures.
try {
Zend_Db_Table::getDefaultAdapter()->getConnection();
} catch (Zend_Exception $e) {
throw new Zend_Exception("A different error");
}
It is because you are on "developing" (exceptions are shown in browser)
Solution 1: Use Production Environment ;)
Solution 2: Change settings in application.ini
Solution 3: Use an try/catch block for database connect