I tried to test mysql's functions with select from command line but find that tab completion does not work
mysql> select Now() as current_moment;
+---------------------+
| current_moment |
+---------------------+
| 2019-12-04 22:11:11 |
+---------------------+
1 row in set (0.00 sec)
mysql> select current_time;
+--------------+
| current_time |
+--------------+
| 22:11:27 |
+--------------+
1 row in set (0.00 sec)
If not reference to the manual, it seems very hard to play around with functions without the assistance of tab completion.
How could activate the tab completion.
Related
I want to get the undo log information but found innodb_trx_undo not exists。have any other tools can i use to anlaysis the undo log files?
mysql> select * from information_schema.innodb_trx_undo;
1109 - Unknown table 'innodb_trx_undo' in information_schema
mysql> select version()
-> ;
+------------+
| version() |
+------------+
| 5.7.36-log |
+------------+
1 row in set (0.01 sec)
This is my table:
+----------+---------------------+
| estimate | timestamp |
+----------+---------------------+
| 05:00:00 | 2015-12-02 13:35:14 |
+----------+---------------------+
1 row in set (0.00 sec)
I am trying to implement a scheduled job to create extra automatic rows every hour to substract the time that has past from the estimated time.
I am able to start the scheduled job and use timediff to calculate the time that has passed since, but i am unable to substract the timediff from the estimated time.
I am guessing that mysql doesn't care much that i want the estimated time column to be stated as a period of time. instead, it just shows me a time without the date.
select timediff(now(),timestamp) from t1;
this gives me the time difference that i need:
+---------------------------+
| timediff(now(),timestamp) |
+---------------------------+
| 00:27:03 |
+---------------------------+
1 row in set (0.00 sec)
but when i do this:
select estimate-timediff(now(),timestamp) as timeleft from t1;
the result is:
+----------+
| timeleft |
+----------+
| 46568 |
+----------+
1 row in set (0.01 sec)
what i would like to get:
+----------+
| timeleft |
+----------+
| 04:32:57 |
+----------+
1 row in set (0.01 sec)
The times may be a little off in my example obviously because of the timediff() but hopefully you understand my issue. There must be an easy solution that i'm missing but i've spent half a day googleing to get to this point but timediff just won't cut me some slack.
Please and thank you!
PS. I haven't found the solution yet but i think i found what might cause the problem. Obvioysly the substraction is done by using absolute values 'estimate' column doesn't use seconds as it's absolute value and the result is completely wrong.
mysql> select abs(estimate) from t1;
+----------+
| abs(estimate) |
+----------+
| 50000 |
+----------+
1 row in set (0.00 sec)
and
mysql> select abs(timediff(now(),timestamp)) from t1;
+--------------------------------+
| abs(timediff(now(),timestamp)) |
+--------------------------------+
| 2318 |
+--------------------------------+
1 row in set (0.00 sec)
So is there an easy way to force mysql to use seconds on a time column? or is something wrong with my table and the estimate format is wrong?
use timediff like that :-
timediff(estimate,timediff(now(),timestamp))
your query :-
select timediff(estimate,timediff(now(),timestamp))
as timeleft from t1;
How many GET_LOCKS can be handled by a mysql server - by the whole server. I wasn´t able to find anything about its limitations.
As per MySQL documentation GET_LOCK() you cannot hold more than one lock per connection.
As it says
If you have a lock obtained with GET_LOCK(), it is released when you
execute RELEASE_LOCK(), execute a new GET_LOCK(), or your connection
terminates (either normally or abnormally).
So essentially, it depends on No.Of connection. I would say the equation would
No.of GET_LOCK handled = NO.Of Connections handled
I see there is a bug logged where people suggested to have concurrent lock per connection. See here http://bugs.mysql.com/bug.php?id=1118
mysql> SELECT GET_LOCK('s',10);
+------------------+
| GET_LOCK('s',10) |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
mysql> SELECT GET_LOCK('t',10);
+------------------+
| GET_LOCK('t',10) |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
mysql> SELECT GET_LOCK('b',10);
+------------------+
| GET_LOCK('b',10) |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
mysql> SELECT IS_FREE_LOCK('b');
+-------------------+
| IS_FREE_LOCK('b') |
+-------------------+
| 0 |
+-------------------+
1 row in set (0.00 sec)
mysql> SELECT IS_FREE_LOCK('t');
+-------------------+
| IS_FREE_LOCK('t') |
+-------------------+
| 1 |
+-------------------+
1 row in set (0.00 sec)
mysql> SELECT IS_FREE_LOCK('s');
+-------------------+
| IS_FREE_LOCK('s') |
+-------------------+
| 1 |
+-------------------+
1 row in set (0.00 sec)
I need to insert file directories into a column but when i select (*) after inserting them all the back slashes have gone. does anyone know how i can do this. it is not possible for me to escape the slashes as i have thousands of records. I thought mysql required the user to do this using a remove_slases or something in php
The easy way to do this in MySQL is by setting the NO_BACKSLASH_ESCAPES SQL mode. Do this for the session with SET SESSION sql_mode='NO_BACKSLASH_ESCAPES';
As such:
mysql> SELECT ##SESSION.sql_mode;
+--------------------+
| ##SESSION.sql_mode |
+--------------------+
| |
+--------------------+
1 row in set (0.00 sec)
mysql> select 'don\t';
+------+
| don |
+------+
| don |
+------+
1 row in set (0.00 sec)
mysql> SET SESSION sql_mode='NO_BACKSLASH_ESCAPES';
Query OK, 0 rows affected (0.00 sec)
mysql> select 'don\t';
+-------+
| don\t |
+-------+
| don\t |
+-------+
1 row in set (0.00 sec)
This allows you to insert c:\bla\tla\bla without the \b or \t being interpreted as a string literal. Also take a look at QUOTE() if you need 'escaping' alike mysql_real_escape_string
More information at http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_no_backslash_escapes
I'm trying to check if a name has invalid characters, so far I've managed to get everything I need apart from checking for capitalization, I've tried using
SELECT BINARY('jiLl') REGEXP('[[:upper:]]+');
but unfortunately that also flags properly formatted names, as in (Jack), is it possible to have the regex ignore the first character of the name, and if so how?
Thank you in advance,
--a
Take one step back and rethink ;)
Give me all instances that don't start with a capital letter and the rest are lower-case:
mysql> SELECT BINARY('JacK') NOT REGEXP('^[[:upper:]][[:lower:]]+$') AS is_invalid;
+------------+
| is_invalid |
+------------+
| 1 |
+------------+
1 row in set (0.00 sec)
mysql> SELECT BINARY('jiLl') NOT REGEXP('^[[:upper:]][[:lower:]]+$') AS is_invalid;
+------------+
| is_invalid |
+------------+
| 1 |
+------------+
1 row in set (0.00 sec)
mysql> SELECT BINARY('Jack') NOT REGEXP('^[[:upper:]][[:lower:]]+$') AS is_invalid;
+------------+
| is_invalid |
+------------+
| 0 |
+------------+
1 row in set (0.00 sec)