I am using cmd to import a table_name.sql file into db2 from UPLOADS sub-folder in the secure_priv path C:\ProgramData using the code below:
mysqlimport -uroot -p ecm2 "C:\ProgramData\MySQL\MySQL Server 8.0\Uploads\table_name.sql"
This table was created in db1 using the following CREATE TABLE and INSERT statements:
CREATE TABLE *table_name* (country varchar(20), country_long VARCHAR(100), Name VARCHAR(100) DEFAULT NULL, gid_no VARCHAR(50) NOT NULL PRIMARY KEY,
cap DOUBLE,
lat DOUBLE,
lng DOUBLE,
p_f VARCHAR(50),
o_f1 VARCHAR(50) DEFAULT NULL,
o_f2 VARCHAR(50) DEFAULT NULL,
o_f3 VARCHAR(50) DEFAULT NULL,
c_year VARCHAR(75),
owner VARCHAR(100),
source VARCHAR(50),
url VARCHAR(200),
gl_source VARCHAR(50),
wepp_id DOUBLE,
year_data DOUBLE,
gen13 VARCHAR(20) DEFAULT NULL,
gen14 VARCHAR(20) DEFAULT NULL,
gen15 VARCHAR(20) DEFAULT NULL,
gen16 VARCHAR(20) DEFAULT NULL,
gen17 VARCHAR(20) DEFAULT NULL,
total_est VARCHAR(20) DEFAULT NULL);
INSERT INTO *table_name* VALUES ('AFG', 'Afghanistan', 'lorem ipsum text', 'GEODB100538', 33.0, 33.0, 66.00, 'type1', '', '', '', '', '', 'GEODB', 'http://comingshortly.com', 'XXODB', 1009793, 2017, '', '', '', '', '', ''
),('AFG', 'Afghanistan', 'lorem ipsum text 2', 'GEODB1040541', 66.0, 55.0, 69.5, 'type2', '', '', '', '', '', 'XXODB', 'http://comingshortly.com', 'GEODB', 1009795, 2017, '', '', '', '', '', ''
);
Table in db1 was exported as .sql file using the mysqldump command in CMD. Pls note I am now trying to import this .sql file into db2 that has a table with same name and schema. When I open the .sql file with Notepad++ I see it does specify the engine and charset specs at the end of CREATE TABLE statement as follows.
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Database and table_name specified in mysqlimport command (uptop) already exist but the import command fails to import the table with the error: Error: 1406, Data too long for column 'country' at row 1, when using table: table_name
'country' happens to be the first column in the table. Values in 'country' col are barely 3 or 4 characters with col length set to VARCHAR(20) while creating the table that was exported to table_name.sql file. The db and table where I am trying to import also had the same col dtype and length specs i.e. VARCHAR(20) Upon experiencing error 1406 I tried changing the col name in the table (not import file) to TEXT from VARCHAR(20). Now it gives a new error: Error: 1261, Row 1 doesn't contain data for all columns, when using table: table_name
FYI- I am using a std installation of MySQL server 8.0.29 on Win 10 machine.
HOW DO I FIX THIS ERROR?