Can't Execute SQL File Event After Disabling Strict Mode - mysql

I'm using Ubuntu 18.04 with Mysql and I'm trying to drop this SQL file:
CREATE TABLE IF NOT EXISTS `ammunition`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`owner` text DEFAULT NULL,
`original_owner` text NOT NULL,
`hash` text NOT NULL,
`weapon_id` char(60) NOT NULL,
`count` int(11) NOT NULL DEFAULT 0,
`attach` text NOT NULL DEFAULT '[]',
PRIMARY KEY (`id`),
UNIQUE KEY `weapon_id` (`weapon_id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4;
I keep getting this error:
SQL ERROR (1101): BLOB, TEXT, GEOMETRY or JSON column attach can't have a default value
I've tried solving it, but the only suggestion I could find was to disable strict mode.
I disabled it permanently:
[mysqld]
sql_mode=""
And restarted the mysql service afterwards.
The temporary way without restart:
set global sql_mode='';
I'm still getting the error message, however. What am I doing wrong?

When you read the error message you see that TEXT..column attach can't have a default value.
To correct this, don't put a default value there.
If you do need a default value, use a VARCHAR column.
Disabling sql strict mode is is worst thing you can do. It will get you into trouble later.

Related

MariaDB: Unknown data type "MYSQL_JSON"

According to MariaDB's website, you can simply replace MySQL with MariaDB.
Great, I thought, however after installing MariaDB (10.5.7), some of my InnoDB tables are corrupt. The error is Unknown data type "MYSQL_JSON".
One of the corrupt tables also says "in use" in phpmyadmin, and I can't access it at all.
So, I was looking for a solution everywhere, and apparently MariaDB doesn't support that type. Is there any way to fix that? There must be some way to covert those columns, right?
I tried to downgrade back to MySQL 5.7, but now MySQL isn't working anymore, so I reinstalled MariaDB again. I couldn't find any downgrade guide either.
Here's a create table statement for the corrupt table, made from my local test-database. I was able to mysqldump all the other ones successfully. Just not this one. Granted, I have a backup from 1 day ago, but losing work from a whole day is not a nice thing regardless.
CREATE TABLE `news` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`author_id` int(10) unsigned DEFAULT NULL,
`title` varchar(180) COLLATE utf8mb4_unicode_ci NOT NULL,
`content` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`excerpt` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sources` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '(DC2Type:json)',
`header` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`copyright` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`category` smallint(5) unsigned DEFAULT NULL,
`featured` tinyint(1) NOT NULL,
`language` smallint(5) unsigned NOT NULL,
`published` datetime DEFAULT NULL,
`status` smallint(5) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `IDX_1DD39950F675F31B` (`author_id`),
CONSTRAINT `FK_1DD39950F675F31B` FOREIGN KEY (`author_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=167 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
The table is auto-generated by Doctrine ORM.
If I could somehow get just a few rows of data out of that table, that would make my week. I just need the content column from the last day.
I got my system back running from my backup. Just those news are missing.
Update
I was able to find a .ibd file under /var/lib/mysql/{mydatabase}/ which contains all the data I needed in plain text. I'm just manually copying the content and insert it back into the database.
To fix Unknown data type "MYSQL_JSON" in the general case when migrating from MySQL to MariaDB.
You have 2 options.
Dump your database from MySQL and import it to MariaDB.
Fix all tables that have a JSON type column.
The first option is straightforward but to go with the second option as suggested by MariaDB website.
stop MySQL service if it is running
sudo service mysql stop
start a new mysql server instance
mysqld --no-defaults --datadir=<Your data dir directory> --lc-messages_dir=./share --plugin-dir=<path to directory containing type_mysql_json.so> --plugin-maturity=alpha
default datadir directory (mysql 5.7, ubuntu 18.04) is /var/lib/mysql/
default plugin directory is /usr/lib/mysql/plugin
while keeping the server running start a new MySQL command-line client and install mysql_json plugin.
install soname 'type_mysql_json';
Alter all tables that have a JSON type column.
ALTER TABLE `database_name`.`table_name` FORCE;
stop MySQL server instance and start MySQL service and everything should be fine.
ps: If you have lots of tables that contains JSON type column (as in my case) you can use this command to get list of all commands you have to run in order to fix all tables
SELECT CONCAT("ALTER TABLE `", TABLE_SCHEMA,"`.`", TABLE_NAME, "` FORCE;") AS MySQLCMD FROM TABLES WHERE TABLE_SCHEMA = "<YOUR_DATABASE_NAME>";
An in-place upgrade of the mysql-5.7 to MariaDB, for the JSON type requires a plugin to read its data format:
Add the following to your MariaDB server configuration:
plugin_load_add=mysql_json=type_mysql_json
plugin_maturity=alpha
Run mysql_upgrade --force to pick up all the JSON data types and convert them.
Alternately just ALTER TABLE news FORCE to change that one table.

Query in Eloquent works when it shouldn't - in MySQL, it fails as expected

If you have an integer field setup in MySQL, no nulls allowed, default null, and you write a query that omits this field, in Laravel the query still executes, and the default value of null isn't used, but instead written as '0'.
If I take the exact, generated query by Eloquent/query builder, and run it in MySQL, it fails, rightly stating that the field in question must have a default value.
Why is there this discrepancy? What the hell is eloquent/query builder/pdo doing?!
create table syntax below:
CREATE TABLE `chapters` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`account_id` int(10) unsigned NOT NULL,
`season_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `chapters_account_id_index` (`account_id`),
KEY `chapters_season_id_index` (`season_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6060 DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci
Doing an insert and omitting account_id in MySQL, fails - as it should. Doing the same in Eloquent/Laravel, does not, despite the generated query being correct.
So I figured out what was going on. Laravel by default sets strict rules to false in config/database.php. This turns off all sorts of options regarding strict mode, such as full group bys, strict trans table.etc.
What we did is set STRICT_ALL_TABLES on our my.cnf and then enforced laravel to strict = true. This solves it.

MySql 5.7 Timestamp works in windows but not on linux

I am trying to create a table using the script down below and getting the error
Error Code: 1067. Invalid default value for 'LAST_MODIFIED_TS.
In my understanding after 5.6 you could create more than one timestamp column also it is not necessary to provide default values . Another thing is it is not barfing at Created_TS which is just one line before it.
Also the same script works on windows but not on linux ubuntu , the version of mysql running on both of them is 5.7
CREATE TABLE testdb.test (
ID BIGINT NOT NULL AUTO_INCREMENT,
DESCRIPTION VARCHAR(300) NOT NULL,
CREATED_TS TIMESTAMP NOT NULL,
LAST_MODIFIED_TS TIMESTAMP NOT NULL,
PROPERTY_TYPE VARCHAR(1) DEFAULT 'S',
last_modified timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT test_pk PRIMARY KEY
(ID) ) ENGINE=InnoDB ;
Make sure you don't have NO_ZERO_DATE sql_mode variable set (http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_zero_date) by running the following query:
show variables like 'sql_mode';

No Able to show content of website on joomla

I have pushed my joomla website content to bigrock serverto host the website. But i am getting the error while hitting the url of website.
Below is the error:
Error displaying the error page: Application Instantiation Error: Table 'resoninr_jooml29.resoninr_session' doesn't exist SQL=SELECT session_id FROM resoninr_session WHERE session_id = 'gqcktvtop2kv33lc28ikjrhi44' LIMIT 0, 1
I am new to joomla and database. Can anybody please help me out to resolve the issue.
Thanks in advance.
if you have all table prefix in the db is "jos83" then replace the value of "$dbprefix" variable with the same prefix as in db("jos83") in the configuration.php at the root of joomla site.
It depends how you have transferred the files and database. Through Akeeba or any third party extension or manually. If you transferred manually then there is less chance of change in public $dbprefix = 'jos83_'; present in configuration file, as you need to change just the database user, database name and hostname in configuration.php file.
Suppose you did through Akeeba then it will ask for a new prefix during site restoration. Suppose you did through Akeeba and still it doesnt work then your session table may be damaged. And if session table is damaged Joomla wont load. You have to manully delete the table and recreate it in phpmyadmin using this sql command
DROP TABLE IF EXISTS `resoninr_session`;
CREATE TABLE IF NOT EXISTS `resoninr_session` (
`username` varchar(150) default '',
`time` varchar(14) default '',
`session_id` varchar(200) NOT NULL default '0',
`guest` tinyint(4) default '1',
`userid` int(11) default '0',
`usertype` varchar(50) default '',
`gid` tinyint(3) unsigned NOT NULL default '0',
`client_id` tinyint(3) unsigned NOT NULL default '0',
`data` longtext,
PRIMARY KEY (`session_id`(64)),
KEY `whosonline` (`guest`,`usertype`),
KEY `userid` (`userid`),
KEY `time` (`time`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Some helpful links
http://forum.joomla.org/viewtopic.php?t=362525
why does joomla 2.5 session table corrupt?
https://www.ostraining.com/blog/joomla/joomla-session-crashed/

Operation not allowed when innodb_forced_recovery > 0 [SqlYog]

I have created a table using SQLyog. When i insert values into it, it pops up following error message:
Operation not allowed when innodb_forced_recovery > 0.
My table consist only four columns including one primary key.
Following is my create and insert queries:
CREATE TABLE `news` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`title` varchar(100) NOT NULL,
`slug` varchar(100) NOT NULL,
`descr` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
insert into `test`.`news` (`title`, `slug`, `descr`)
values ('titleOne', 'slugOne', 'descOne')
This error is comes when MySQL is in Read only mode.
Edit file /etc/my.cnf.
And comment out following line
# innodb_force_recovery = 1
Apparently this setting causes innodb to become read-only. If you don't have access to /etc/my.cnf on shared hosting, ask your host to fix it for you. When it's commented out or non-existent in /etc/my.cnf, the it reverts to a default setting of 0.
This happens to me also but what i did was to change the SQL Engine during creatng the table from InnoDB to MyISAM
like in
ENGINE=innoDB to ENGINE=MyISAM
So if you have your database and want to upload it, open it with any editor and change the engine at the end of each table from innoDB to MyISAM.
this resolved the problem.