How to revert or undo ALLOW_INVALID DATES - mysql

Hello i got an error when im about to insert datas to a column a tutorial in google said to use
SET SQL_mode= 'ALLOW_INVALID DATES'
Now I got error 1265 Data truncated for column 'BDAY' And the BDAY column now shows 0000-00-00
How do I revert it back to normal or do I just reinstall mysql?
Thanks so much

If you have changed the sql_mode on your configuration files, you can run below command on Linux to find the changes:
sudo grep -ir "ALLOW_INVALID DATES" /etc/
sudo grep -ir "ALLOW_INVALID DATES" /etc/mysql/
Default configuration files on Linux are stored on the etc folder.
On your configuration file set sql_mode to save it permanently:
[mysqld]
sql-mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
On the MySQL command line you can set it for the session and global.
First check using:
mysql> show variables like '%sql_mode%';
+---------------+-----------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value |
+---------------+-----------------------------------------------------------------------------------------------------------------------+
| sql_mode | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
+---------------+-----------------------------------------------------------------------------------------------------------------------+
mysql> show global variables like '%sql_mode%';
+---------------+-----------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value |
+---------------+-----------------------------------------------------------------------------------------------------------------------+
| sql_mode | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
+---------------+-----------------------------------------------------------------------------------------------------------------------+
Then you change it using:
SET GLOBAL sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

Related

mysql 1290: have set "secure_file_priv" and used absolute path

System: Centos
Vesion:
Server version: 5.5.56-log Source distribution
What I did:
Have set the secure_file_priv in my /etc/my.cnf
mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+---------------+
| Variable_name | Value |
+------------------+---------------+
| secure_file_priv | /target_file |
+------------------+---------------+
Have restarted myssql service by service mysql restart, and inaddition I have restart the server/machine too
and I set chmod 777 /target_file
But I still get
>> select * from mytable into outfile '/target_file/config';
>> ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
Did I miss something?

Storing base64_encoded data in MySQL

I am trying to insert base64_encoded data in Db, but it says 'Mysql server has gone'. I have taken Blob type for inserting data then also it is not inserting.
set max_allowed_packet to a higher value (your value * x) in the /etc/my.cnf and restart the server and try again
check before and after restart
MariaDB [your_schema]> show variables like 'max_allowed_packet';
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+

How to show all user-defined variables (MySQL)

I set two user-defined variables as shown below but after some time, I forgot the names:
SET #a = 2, #b = 3;
So, does MySQL have the command that displays all user-defined variables?
Starting with MySQL 5.7, the performance schema exposes user variables.
See table performance_schema.user_variables_by_thread
https://dev.mysql.com/doc/refman/5.7/en/performance-schema-user-variable-tables.html
If you have MariaDB (a binary "drop-in" equivalent of MySQL) there is a plugin available, provided by MariaDB itself.
MariaDB 10.2 (equivalent to MySQL 5.7) and above has a plugin that creates a "USER_VARIABLES" table.
Here is how to install the plugin.
Here is an example of its use:
SELECT * FROM information_schema.USER_VARIABLES ORDER BY VARIABLE_NAME;
+---------------+----------------+---------------+--------------------+
| VARIABLE_NAME | VARIABLE_VALUE | VARIABLE_TYPE | CHARACTER_SET_NAME |
+---------------+----------------+---------------+--------------------+
| var | 0 | INT | utf8 |
| var2 | abc | VARCHAR | utf8 |
+---------------+----------------+---------------+--------------------+
MariaDB installs the plugin by default after version MariaDB 10.2.6.
The link above shows how to install it for prior versions.
Double check what version of "mysql" you're running, because sometimes people will refer to a MariaDB as MySQL, due to its use as a "binary drop in replacement" for MySQL. So it's possible that you are running a MariaDB database.
I am not aware of MySQL providing anything similar.
How to check which version of mysql you're running (the prompt is in bold)
From the command line:
$ mysql -v
From the mysql command client:
mysql> SHOW VARIABLES LIKE "%version%";
It is also shown when you first log into the mysql command client, which you can do via:
$ mysql -u your_mysql_username --password=your_mysql_password
With performance_schema.user_variables_by_thread, you can show all user-defined variables as shown below:
mysql> SELECT * FROM performance_schema.user_variables_by_thread;
+-----------+---------------+--------------------------------+
| THREAD_ID | VARIABLE_NAME | VARIABLE_VALUE |
+-----------+---------------+--------------------------------+
| 69 | first_name | 0x4A6F686E |
| 69 | last_name | 0x536D697468 |
+-----------+---------------+--------------------------------+

set mysql session and global sql_mode when service start

I am using mysql Server version: 5.5.37 and in current mysql whenever i will restart mysql service that time i saw below results
mysql> select ##GLOBAL.sql_mode;
+--------------------------------------------+
| ##GLOBAL.sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+
1 row in set (0.00 sec)
mysql> select ##session.sql_mode;
+--------------------------------------------+
| ##session.sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+
1 row in set (0.00 sec)
But i want to set mysql mode for both(session as well as global) whenever service is restart.i have also tried to put below line in /etc/my.cnf file
but its not working fine
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION
so is it possible to set from any core file or else where ?
please shine on this topic
i need help to set up session and global both sql_mode to 'NO_ENGINE_SUBSTITUTION'
This is how I set SQL mode in my /etc/my.conf file:
[mysqld]
sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Make sure your MySQL daemon has permissions to read this file. Also, check if there are any other my.conf files that may override your value. MySQL searches and reads config files in multiple locations. Read more here http://dev.mysql.com/doc/refman/5.7/en/option-files.html

Mysql binlog path from mysql console

Is there a way to know the bin log files path from mysql console as we can know whether its ON or OFF by using
Select * information_schema.GLOBAL_VARIABLES
where variable_name like '%log_bin%'.
Use this to show on/off:
SHOW VARIABLES LIKE 'log_bin'
Also:
SHOW GLOBAL VARIABLES LIKE '%bin%'
Or
SHOW SESSION VARIABLES LIKE ...
More Information: (notice that some of these values and results changed from 5.5 to 5.6!)
http://dev.mysql.com/doc/refman/5.5/en/show-master-status.html
mysql > SHOW MASTER STATUS;
+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| mysql-bin.003 | 73 | test | manual,mysql |
+---------------+----------+--------------+------------------+
mysql> SHOW BINARY LOGS;
+---------------+-----------+
| Log_name | File_size |
+---------------+-----------+
| binlog.000015 | 724935 |
| binlog.000016 | 733481 |
+---------------+-----------+
From the docs regarding log-bin"
Setting this option causes the log_bin system variable to be set
to ON (or 1), and not to the base name. This is a known issue;
see Bug #19614 for more information.
There is a workaround using mysqld instead in the Bug 19614 which I modified a bit. If you are scripting, you can use from the mysql client (which I found a bit tedious to do, see the next workaround):
mysql >\! dirname $(mysqld --help --verbose 2> /dev/null | egrep "^log-bin " | grep -o "\/.*")
Looks like there is a patch submitted by Mark Callaghan, and it was never committed. There is a function in WP5465 (which is the work in progress for this patch), however it didn't work properly for me, as the location of the logs can be different across setups.