mysql - 1054 Unknown column in field list - mysql

I have looked on stackoverflow and the mysql and Plantmysql forums
Nobody has quite been able to answer this.
Steps
I created a CSV from an Excel file
Imported using the Table Data Import Wizard in MySQL
I am able to run
SELECT * FROM apporteur_mapping_table;
However I get Error Code 1054 when I run
SELECT broker_code FROM apporteur_mapping_table;
Field type is VARCHAR(20)
Update #2 - output from SHOW Create Table
CREATE TABLE `apporteur_mapping_table` (
`broker_code` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
`broker_name` text COLLATE utf8_unicode_ci,
`date_de_creation_de_code` text COLLATE utf8_unicode_ci,
`commercial_contact_name` text COLLATE utf8_unicode_ci,
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1690 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
3 Resolved
I seem to have been able to resolve it by Creating the table in code from scratch. It seems using the Table Data Import Wizard in mysql caused the data to have some interpretation
I am using MySQL Workbench 6.3 on Windows 10
Annotation can be found here
Link to CSV source here
Anyone able to help?

Related

MySQL Character Set and Collate

I use MySQL 5.7, but I do not know how to config it to display Vietnamese correctly.
I have set
CREATE DATABASE brt
DEFAULT CHARACTER SET utf8 COLLATE utf8_vietnamese_ci;
After that I used "LOAD DATA LOCAL INFILE" to load data written by Vietnamese into the database.
But I often get a result with error in Vietnamese character display.
For the detailed codes and files, please check via my GitHub as the following link
https://github.com/fivermori/mysql
Please show me how to solve this. Thanks.
As #ysth suggests, using utf8mb4 will save you a world of trouble going forward. If you change your create statements to look like this, you should be good:
CREATE DATABASE `brt` DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
USE `brt`;
DROP TABLE IF EXISTS `fixedAssets`;
CREATE TABLE IF NOT EXISTS `fixedAssets` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`code` varchar(250) UNIQUE NOT NULL DEFAULT '',
`name` varchar(250) NOT NULL DEFAULT '',
`type` varchar(250) NOT NULL DEFAULT '',
`createdDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE INDEX `idx_fa_main` ON `fixedAssets` (`code`);
I've tested this using the data that you provided and get the expected query results:
name
----------------------------------------------------------------
Mould Terminal box cover BN90/112 612536030 39 tháng
Mould W2206-045-9911-VN #3 ( 43 tháng)
Mould Flange BN90/B5 614260271 ( 43 tháng)
Mould 151*1237PH04pC11 ( 10 năm)
Transfer 24221 - 2112 ( sửa chữa nhà xưởng Space T 07-2016 ) BR2
Using the utf8mb4 character set and utf8mb4_unicode_ci collation is usually one of the simpler ways to ensure that your database can correctly display everything from plain ASCII to modern emoji and everything in between.

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.

Error when uploading MySQL database to phpMyAdmin [duplicate]

This question already has answers here:
phpMyAdmin "No database selected" MySQL
(7 answers)
Closed 4 years ago.
I apologize if this is simple. This seems to be a somewhat common error.
I'm trying to upload the MySQP database to phpMyAdmin and am getting the following error message. From what I read on other posts, it's probably as simple as a comma, but I can't figure it out. Any help is much appreciated!
SQL query:
-- Table structure for table `wp_eaet_commentmeta`
--
CREATE TABLE IF NOT EXISTS `wp_eaet_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL,
`comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`meta_value` longtext COLLATE utf8mb4_unicode_ci
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
MySQL said:
1046 - No database selected
As the error says
MySQL said:
1046 - No database selected
Select a database first from list of the databases in phpmyadmin then upload

Importing a MySQL database

Trying to import a MySQL database using PHP-Admin. When I try to import the file backed-up by my host, I get this error message:
SQL query:
DROP TABLE IF EXISTS `wp_commentmeta`
MySQL said: Documentation
#1046 - No database selected
I have also tried to export the database myself, then trying to import that specific file. When I do that, however, I get a completely different error message:
SQL query:
CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL,
`comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`meta_value` longtext COLLATE utf8mb4_unicode_ci
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
MySQL said: Documentation
#1046 - No database selected
What can I do to resolve this?
You need to USE a database. You could edit your file and add the line at the top, something like:
USE databasename;
Some tools will let you set a default database when restoring from backup. If you haven't selected one that could be a problem.
If you haven't created a database you'll need to do that first.
You need to select which database you are importing to in your SQL. Your first statement should be:
USE DATABASE `db_name`;
You have no database selected.
Find which databases exist
SHOW DATABASES:
and then select one for use
USE `database_name`
You say that you are importing into a new host, so I would assume that you do not already have a database created;
CREATE DATABASE `database_name`
Now you can USE that database you just created; and your queries should now work.

What does this error in MySQL mean?

I am using the Zymic Database Uploader v1.1 to upload my XAMPP/MySQL database to zymic database.
I followed the instruction carefully until I got this error.
Error at the line 27: ) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci MAX_ROWS=15000;
Query: CREATE TABLE `bmf_chatting` (
`usr_id` int(11) NOT NULL,
`usr_name` varchar(255) collate latin1_general_ci NOT NULL,
`chatto` int(11) NOT NULL,
`timestamp` int(11) NOT NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci MAX_ROWS=15000;
MySQL: Table 'bmf_chatting' already exists
This happened while I was Processing/Importing the database into Zymic but it stopped on error. I have no database yet in my zymic and I have no duplicate table 'bmf_chatting'.
I thought it will be a simple export/import. :(
Check your dump file, if this table didn't get exported twice for whatever reason.
Also make sure, to drop all tables (and maybe the entire database) before you retry with you import. Whatever tables are created above this one, have already been created.
It sounds like you had a table called bmf_chatting in MySQL before and it was improperly deleted (the files were probably deleted without dropping the database).
Try running a drop database query before your create query.