My table looks like
create table try ( name varchar(8), CREATED_BY varchar(40) not null);
and then I have a trigger to auto populate the CREATED_BY field
create trigger autoPopulateAtInsert BEFORE INSERT on try for each row set new.CREATED_BY=user();
When I do an insert using
insert into try (name) values ('abc');
the entry is made in the table but I still get the error message
Field 'CREATED_BY' doesn't have a default value Error no 1364
Is there a way to suppress this error without making the field nullable AND without removing the triggfer? Otherwise my hibernate will see these exceptions ( even though the insertions have been made) and then application will crash.
This is caused by the STRICT_TRANS_TABLES SQL mode defined in the
%PROGRAMDATA%\MySQL\MySQL Server 5.6\my.ini
file. Removing that setting and restarting MySQL should fix the problem.
See https://www.farbeyondcode.com/Solution-for-MariaDB-Field--xxx--doesn-t-have-a-default-value-5-2720.html
If editing that file doesn't fix the issue, see http://dev.mysql.com/doc/refman/5.6/en/option-files.html for other possible locations of config files.
Open phpmyadmin and goto 'More' Tab and select 'Variables' submenu.
Scroll down to find sql mode.
Edit sql mode and remove 'STRICT_TRANS_TABLES'
Save it.
In phpmyadmin, perform the following:
select ##GLOBAL.sql_mode
In my case, I get the following:
ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES ,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Copy this result and remove STRICT_TRANS_TABLES. Then perform the following:
set GLOBAL sql_mode='ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
Set a default value for Created_By (eg: empty VARCHAR) and the trigger will update the value anyways.
create table try (
name varchar(8),
CREATED_BY varchar(40) DEFAULT '' not null
);
When I had this same problem with mysql5.6.20 installed with Homebrew, I solved it by going into my.cnf
nano /usr/local/Cellar/mysql/5.6.20_1/my.cnf
Find the line that looks like so:
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
Comment above line out and restart mysql server
mysql.server restart
Error gone!
Run mysql console:
mysql -u your_username -p
, select database:
USE your_database;
and run (also from mysql console):
SET GLOBAL sql_mode='';
That will turn off strict mode and mysql won't complain any more.
To make things clear: your database definition says "this field must have default value defined", and by doing steps from above you say to MySql "neah, just ignore it". So if you just want to do some quick fix locally this solution is ok. But generally you should investigate in your database definition and check if field really needs default value and if so set it. And if default value is not needed this requirement should be removed to have clean situation.
As others said, this is caused by the STRICT_TRANS_TABLES SQL mode.
To check whether STRICT_TRANS_TABLES mode is enabled:
SHOW VARIABLES LIKE 'sql_mode';
To disable strict mode:
SET GLOBAL sql_mode='';
Before every insert action I added below line and solved my issue,
SET SQL_MODE = '';
I'm not sure if this is the best solution,
SET SQL_MODE = ''; INSERT INTO `mytable` ( `field1` , `field2`) VALUES ('value1', 'value2');
Modify your query and add "IGNORE" as:
INSERT IGNORE INTO `mytable` ( `field1` , `field2`) VALUES ('value1', 'value2');
Its work and tested Copy to Config File: /etc/mysql/my.cnf OR /bin/mysql/my.ini
[mysqld]
port = 3306
sql-mode=""
then restart MySQL
This appears to be caused by a long-standing (since 2004) bug (#6295) in MySQL, titled
Triggers are not processed for NOT NULL columns.
It was allegedly fixed in version 5.7.1 of MySQL (Changelog, last entry) in 2013, making MySQL behave as “per the SQL standard” (ibid).
For Windows WampServer users:
WAMP > MySQL > my.ini
search file for sql-mode=""
Uncomment it.
In Windows Server edit my.ini (for example program files\mysql\mysql server n.n\my.ini)
I would not simply set the sql-mode="", rather I suggest one removes STRICT_TRANS_TABLES from the line, leave everything as-was, and then restart MySQL from the services utility. Add a comment for future programmers who you are and what you did.
Most of these answers are a lot of work for the not-seasoned coder. Like mentioned the issues is with STRICT_TRANS_TABLES.
First verify STRICT_TRANS_TABLES is running.
$ mysql -u root -p -e "SHOW VARIABLES LIKE 'sql_mode';"
You can disable strict mode on your MySQL server by running the following command on your Linode's command line:
$ mysql -u root -p -e "SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';"
Then, you can verify that the mode is set by running the following:
$ mysql -u root -p -e "SELECT ##GLOBAL.sql_mode;"
This answer was found here https://www.linode.com/community/questions/17070/how-can-i-disable-mysql-strict-mode
i set the fields to not null and problem solved, it updates when an information is commanded to store in it, no more showing msqli message that the field was empty cus you didnt insert value to it, well application of this solution can work on some projects depends on your project structure.
This is for SYNOLOGY device users:
How to set global variables (strict mode OFF) on SYNOLOGY device.
(checked on DSM 7.0.1-42218 - device model DS418)
Used PUTTY to connect:
login as root and
sudo su after... (to be admin total)
if not exist create my.cnf in:
MariaDB 5:
/var/packages/MariaDB/etc
MariaDB 10:
/var/packages/MariaDB10/etc
this should be in the file (at least for strict mode off)
# custom configs
[mysqld]
innodb_strict_mode = OFF
sql_mode = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
restart mysqld daemon:
MariaDB 5:
/usr/syno/bin/synopkg restart MariaDB
MariaDB 10:
/usr/syno/bin/synopkg restart MariaDB10
check for strict mode enabled at these two global options - both should be not there or off (see config above)
log into mysql:
mysql -u root -p
enter password:
show variables like 'sql_mode';
show variables like '%STRICT%';
i solved problem changing my.ini file located in data folder. for mysql 5.6 my.ini file moved to data folder rather the bin or mysql installation folder.
I think in name column have null values in this case.
update try set name='abc' where created_by='def';
I am using Xampp 7.3.28-1 for Linux. It uses MariaDB 10.4.19. Its configuration file is:
/opt/lampp/etc/my.cnf
It does NOT contain an entry that defines sql_mode.
However the query "select ##GLOBAL.sql_mode;" does return a result and it contains the problematic STRICT_TRANS_TABLES. I guess it is by default now.
My solution was to explicitly define the mode by adding this line below [mysqld]:
sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
You can define the modes that you need or just leave it blank.
I found that once I removed what was a doubling up of a foreign key and primary key, when I could have just used the foreign key as the primary key alone in the table. All my code then worked and I was able to upload to db.
So I am stuck with this error when trying to connect my node.js application with MySQL.
It won't let me connect to MySQL from localhost, not a single command is working.
The MySql workbench also says the same
I can't use any database commands since it's not letting me access mysql. Gone through almost all possible solutions on the internet none of them worked. Please help me out here even an explanation for this would help if not the solution.
In order to access you must do the following steps :
1. Run the terminate with user permission.
2. Access the path where you have mysql installed.
3. Put the following sentence.
mysql.exe -u root -ppasw
-u : It is the user.
-p : the password but next to the p without space.
If it does not work try this in windows cmd
To restore to a single concrete database.
mysqlbinlog -database='yourFile.00004'
Explanation : The Binary log.
It has replaced the old update file.
Its mission is to update the DBs during a recovery operation.
Replication masters are used as a reminder of the statements to be sent to the slave servers.
If the name is not specified, the host is chosen.
Performance drop of 1%.
Active bins must not be opened during execution.
If you put extension to the file, it is ignored.
A new BIN_LOG file is created when :
The server is restarted
A Flush binary Logs is made
The size specified in MAX_BINLOG_SIZE is exceeded.
The files that are generated have an extension that are sequential numbers and represent the order (index) of their creation controlled by the name host_name.index.
To activate and decomment the log-bin my.ini directive. If log-bin=file is used, that name will be used to name the sequence of files.
To delete index files.
purge binary before date-time (in this format "yyyy-mm-dd hh:mm:ss" or now() or interval....)
purge binary logs to filename; deletes up to this file (this one not included)
reset master -> deletes all files
To disable the binary log, the session variable is used.
SQL_LOG_BIN : Up to version 5.6 this one is
EXECUTE DB : binlog-do-db=BD
DOES NOT RUN DB : binlog-ignore-db=BD
The commands are the continuation of the binary log.
create database
alter database
drop database
To see the content of a binary file (must not be open).
mysqlbinlog "file with its path".
To restore several binary files must be done in one step.
mysqlbinlog file1 file2 file3 file3 | mysql -u root -ppassword
To restore.
Overwrite the file >
Adds in the content respecting the content >>
To restore to a single concrete database.
mysqlbinlog -database='filenamebinlog.00004'
If the above does not work, do this first
Another option
ERROR 1130 (HY000): Host 'localhost' is not allowed to connect to this MySQL server
Cause :
mysql only has one root user, select MD5 after changing root password, then submit, reboot.
Login appears "The host 'localhost' is not allowed to connect to this MySQL server..."
Try the user table in another mysql library, overwrite, no, it is estimated that the version is different
Resolve :
Edit my.ini
Add a sentence to [mysqld]: skip-grant-tables
For example :
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-name-resolve
skip-grant-tables
The purpose is :
Bypass MySQL access control, anyone can log in to the MySQL database as an administrator in the console.
It should be noted that after changing the password, the MySQL server must be stopped and restarted to take effect.
Restart the mysql service!
My MySQL CLI client when connecting to a database is automatically showing the data as hex
Connecting in CLI using mysql -u user -p'password' -h host -P port --ssl-mode=DISABLED
To turn this off I have to run it with the --skip-binary-as-hex option to see the data properly
Need help understanding what is causing this is getting enabled by default.
This issue does not exist for other users logging into the same database and is not an issue for me I connect through a DB tool, it occurs only on CLI
Prior to MySQL 8.0.19, the issue which you are facing did not exist. binary-as-hex client option is enabled by default from MySQL 8.0.19 Command Line Client.
Run status or \s in MySQL Command Line Client. You will notice a line about binary data like this:
Binary data as: Hexadecimal
You can refer these links for more information:
https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_char
https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html#option_mysql_binary-as-hex
After I upgraded MySQL 5.7 to MySQL 8.0, I started MySQL again and I got an error:The user specified as a definer ('mysql.infoschema'#'localhost') does not exist' when trying to dump tablespaces.
I don't understand why this problem occurs. And I want to know how to solve it
I had the same error when I accidentally downgraded my MySQL version from 8 to 5.7. At the first start the older version broke something so that version 8 was showing the error above.
In my case I had to enter the docker container where MySQL was running first
docker exec -it mysql bash
Then I basically followed the steps here
mysql -u root -p
mysql> SET GLOBAL innodb_fast_shutdown = 1;
mysql_upgrade -u root -p
This took some minutes but then everything was working again.
It may occur after some time after you set up your new system.
As a suggested solution, just try on Windows
1) open cmd.exe as Administrator
2) run mysql_upgrade.exe -uyour_user_name -pyour_password
mysql_upgrade.exe can be located at
C:\Program Files\MySQL\MySQL Server 8.0\bin
Then run the following to see if the infoschema user has appeared.
select user, host from mysql.user;
In my case, such error was caused by that I had changed the host of the dba user from % to localhost to strengthen the security.
I used "abcdba" with DDL right to create db schema, and used "abc" with CURD right for the Web service to use the DB. After the change, the read operations were OK but the write operations failed with the error message in the OP.
Flush privilege or restarting the server did not solve the problem. Then I changed to host of the dba user back to %. Then things have become normal again.
Apparently mysql does not like the changes of host of the dba user, and existing databases created by that dba user will have problem if the host of the dba user is changed.
Essentially, changing the host of the dba user is actually removing user abcdba#% and creating a new user abcdba#localhost. Here had come the error message, since abcdba#% and abcdba#localhost are 2 differently fully qualified usernames.
I tried to load code examples from http://examples.oreilly.com/9780596527082/. This approach don't work for me:
Limbs.sql can be found in recipies/tables (this is example from book).
I work on ver. 5.6.24 (localhost) and Windows 7.
There are two ways to execute an external file on your database:
1. From the command line
2. From within the MySQL client
First, to identify which application you are using (The DOS command line, or the MySQL client application), look at your prompt. When you are within the MySQL client, your prompt will say:
mysql>
You get that window/prompt by double clicking the MySQL client application. This is the prompt I see in your provided screenshots.
If you're in the windows command line, your prompt will say something like:
C:\Users\kulis>
You get to the Windows Command Line by typing "cmd" in the Windows start menu, or searching for it within the Start menu.
To execute an external script in the MySQL client application (which is where you are in your screenshots), you'll need to use the "source" command:
mysql> source \path\to\your\script\limbs.sql
Alternately, if you use the Windows Command Line, you can use the command you've already tried:
c:\Users\kulis> cd D:\Nauka\SQL\bazy\recipes\tables
D:\Nauka\SQL\bazy\recipes\tables> mysql -uroot -pcookbook < limbs.sql
Source:
http://dev.mysql.com/doc/refman/5.6/en/mysql-batch-commands.html
mysql -uroot -pYOUR_PASSWORD test77db < this.sql
no space after -u and -p. A space there can really confuse mysql.
so it looks like mysql -uroot -pYOUR_PASSWORD test77db < this.sql
this runs this.sql against test77db
be careful using root
a better example would be mysql -ujohn -popen_sesame test77db < this.sql
where user is john and password=opensesame
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
follow along below in my make-believe database:
in my example test77db is the database name. so my .sql file does not need to reference the dbname cause you are passing it at shell. but put it in there anyway as a use stmt. i will show u
get into mysql with authorization to create a database, perhaps as root, whatever.
so now you are at a mysql prompt.
example below in database test77db:
use test77db; -- just for kicks to emphasize the point
CREATE TABLE bonehead
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
who_is_bonehead VARCHAR(100) NOT NULL
);
you just created the table, now quit mysql
you are now at an operating system (linux,dos,whatever) prompt
create this.sql text file, it merely contains:
use test77db;
insert into bonehead(who_is_bonehead) values('Drew Pierce');
save it.
then run (you are still at an operating system prompt!)
mysql -uroot -pYOUR_PASSWORD test77db < this.sql
you are now at a mysql prompt, enter
use test77db; -- this is the database name
select * from bonehead;