MariaDB [(none)]> SET #good = 10;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SHOW VARIABLES LIKE 'good';
Empty set (0.07 sec)
HOW show list all variables initialized by SET operator ?
For MySQL, use this:
select * from performance_schema.user_variables_by_thread;
MySQL Demo:
mysql> SET #good = 10;
Query OK, 0 rows affected (0.00 sec)
mysql> SET #bad = 0;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from performance_schema.user_variables_by_thread;
+-----------+---------------+----------------+
| THREAD_ID | VARIABLE_NAME | VARIABLE_VALUE |
+-----------+---------------+----------------+
| 36922 | bad | 0 |
| 36922 | good | 10 |
+-----------+---------------+----------------+
2 rows in set (0.00 sec)
For MariaDB, it is not supported so far:
https://mariadb.com/kb/en/mariadb/information-schema-user_variables-table/
The USER_VARIABLES table will be introduced in MariaDB 10.2.0 as part of the user_variables plugin.
Related
My stored procedure has IN parameter for page number (IN page INT)
And everything works fine for any value <= 2147483647.
And if value is > 2147483647 I get error 1264.
All this happens on 5.6.26 Community Server compiled for Linux (x86_64) and the same for 5.6.24 Community Server compiled for Win64 (x86_64)
And all of the above is fine and I understand the error.
However, on server 5.6.30-1+deb.sury.org~xenial+2 (Ubuntu) compiled for debian-linux-gnu (x86_64) this is not reproduced. Input value is just cut to 2147483647 no matter what value I pass there.
What setting is responsible for this "auto max value cap"? How can I synchronize settings on different environments without re-installation to have the same behavior?
Thank you!
Check 5.1.7 Server SQL Modes.
mysql> SELECT ##GLOBAL.SQL_MODE, ##SESSION.SQL_MODE;
+--------------------------------------------+--------------------------------------------+
| ##GLOBAL.SQL_MODE | ##SESSION.SQL_MODE |
+--------------------------------------------+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+--------------------------------------------+
1 row in set (0.00 sec)
mysql> DELIMITER //
mysql> DROP PROCEDURE IF EXISTS `sp_test`//
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> CREATE PROCEDURE `sp_test`(IN `page` INT)
-> BEGIN
-> SELECT `page`;
-> END//
Query OK, 0 rows affected (0.00 sec)
mysql> DELIMITER ;
mysql> CALL `sp_test`(2147483647);
+------------+
| `page` |
+------------+
| 2147483647 |
+------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> CALL `sp_test`(2147483648);
ERROR 1264 (22003): Out of range value for column 'page' at row 1
mysql> SET ##SESSION.SQL_MODE = 'NO_ENGINE_SUBSTITUTION';
Query OK, 0 rows affected (0.00 sec)
mysql> select ##GLOBAL.SQL_MODE, ##SESSION.SQL_MODE;
+--------------------------------------------+------------------------+
| ##GLOBAL.SQL_MODE | ##SESSION.SQL_MODE |
+--------------------------------------------+------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+------------------------+
1 row in set (0.00 sec)
mysql> CALL `sp_test`(2147483648);
+------------+
| `page` |
+------------+
| 2147483647 |
+------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> SHOW WARNINGS;
+---------+------+-----------------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------------+
| Warning | 1264 | Out of range value for column 'page' at row 1 |
+---------+------+-----------------------------------------------+
1 row in set (0.00 sec)
When I use CREATE TABLE tbl_name I can only specify a table in database I currently use.
Is there any way to CREATE TABLE tbl_name in database1 without a prior USE database1?
Try:
mysql> CREATE DATABASE `test_1`;
Query OK, 1 row affected (0.00 sec)
mysql> CREATE DATABASE `test_2`;
Query OK, 1 row affected (0.00 sec)
mysql> SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| NULL |
+------------+
1 row in set (0.00 sec)
mysql> CREATE TABLE `test_1`.`table_1` (`column_1` BOOL);
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE `test_2`.`table_2` (`column_1` BOOL);
Query OK, 0 rows affected (0.01 sec)
mysql> USE `test_1`;
Database changed
mysql> SHOW TABLES;
+------------------+
| Tables_in_test_1 |
+------------------+
| table_1 |
+------------------+
1 row in set (0.00 sec)
mysql> USE `test_2`;
Database changed
mysql> SHOW TABLES;
+------------------+
| Tables_in_test_2 |
+------------------+
| table_2 |
+------------------+
1 row in set (0.00 sec)
Recreating SQLs:
drop table t1;
set sql_mode = '';
create table t1 (c1 int, c2 int);
set sql_warnings = 0;
SHOW VARIABLES LIKE '%sql_warnings%';
insert into t1 values(1,'b');
set sql_warnings = 1;
SHOW VARIABLES LIKE '%sql_warnings%';
insert into t1 values(1,'b');
Output:
mysql> create table t1 (c1 int, c2 int);
Query OK, 0 rows affected (0.01 sec)
mysql> set sql_warnings = 0;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE '%sql_warnings%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_warnings | OFF |
+---------------+-------+
1 row in set, 1 warning (0.01 sec)
mysql> insert into t1 values(1,'b');
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql>
mysql> set sql_warnings = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE '%sql_warnings%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_warnings | ON |
+---------------+-------+
1 row in set, 1 warning (0.00 sec)
mysql> insert into t1 values(1,'b');
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.8-rc |
+-----------+
1 row in set (0.00 sec)
From the output, no matter setting sql_warnings to 0 or 1, I am always getting the warnings in the INSERT statement.
Anyone knows why?
Update:
Result for "SHOW VARIABLES LIKE '%sql_warnings%';" is added above.
Filed a bug to MySQL and they verified it as a bug from version 5.0 to 5.7.
http://bugs.mysql.com/bug.php?id=80404
I am curious why this obvious behavior is not found before.
I have a column in a table that contains the path for a file, along the lines of:
/here/here2/something.jpg
I need to change every row to map it to:
/here3/something.jpg
Is there an easy way to do this? Thanks!
You don't need regex for this. Simple string functions can do the trick. You could use a query like this:
update test set path=concat('/here3/',
substring(path, length('/here/here2/') + 1))
where path like '/here/here2/%';
Here is a little test case to prove it works:
mysql> create table test (path varchar(64));
Query OK, 0 rows affected (0.02 sec)
mysql> insert into test (path) values
-> ('/here/here2/something.jpg'),
-> ('/here/here2/something-else.jpg'),
-> ('/here/here2/yet-another-something.jpg');
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from test;
+---------------------------------------+
| path |
+---------------------------------------+
| /here/here2/something.jpg |
| /here/here2/something-else.jpg |
| /here/here2/yet-another-something.jpg |
+---------------------------------------+
3 rows in set (0.00 sec)
mysql> update test set path=concat('/here3/',
-> substring(path, length('/here/here2/') + 1))
-> where path like '/here/here2/%';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> select * from test;
+----------------------------------+
| path |
+----------------------------------+
| /here3/something.jpg |
| /here3/something-else.jpg |
| /here3/yet-another-something.jpg |
+----------------------------------+
3 rows in set (0.00 sec)
First of all, are you familiar with using PHP? You could write a script to get all of the entries from the database, and then change them using preg_replace(). Then you could use mysql to update the database.
Can there any way to insert a hex value into MYSQL?
I also want to be able to retreive it in hex form.
For example, something like:
INSERT INTO table ( hexTag )
VALUES ( HEX(0x41) );
And if I do this, I want it to put an 'A' into the table
For that particular use case, you can either insert the hex value directly and it will be interpreted as a string, or use HEX() to input and UNHEX() to output
mysql> create table hexTable(pseudoHex varchar(50));
Query OK, 0 rows affected (0.01 sec)
mysql> insert into hexTable values (0x41);
Query OK, 1 row affected (0.00 sec)
mysql> select * from hexTable;
+-----------+
| pseudoHex |
+-----------+
| A |
+-----------+
1 row in set (0.00 sec)
mysql> select HEX(pseudoHex) from hexTable;
+----------------+
| HEX(pseudoHex) |
+----------------+
| 41 |
+----------------+
1 row in set (0.00 sec)
mysql> delete from hexTable;
Query OK, 1 row affected (0.00 sec)
mysql> insert into hexTable values (HEX('A'));
Query OK, 1 row affected (0.00 sec)
mysql> select UNHEX(pseudoHex) from hexTable;
+------------------+
| UNHEX(pseudoHex) |
+------------------+
| A |
+------------------+
1 row in set (0.00 sec)
mysql> select * from hexTable;
+-----------+
| pseudoHex |
+-----------+
| 41 |
+-----------+
1 row in set (0.00 sec)
See these links.