In order to import data from a CSV file the file should be placed in a specific system defined directory. To find the path of that directory, use the following SQL command:
SHOW VARIABLES LIKE "secure_file_priv";
An output example of the response would be:
/var/lib/mysql-files
Copy the CSV file to the proper directory
You should copy the CSV file to that directory (it may require sudo):
sudo data.csv /var/lib/mysql-files
Import the data from the CSV
After you have placed the file there, you can import data use the following snippet:
LOAD DATA INFILE '/var/lib/mysql-files/data.csv' INTO TABLE my_table FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS;
Use Ignore row if the file contains a header. Configure the other options accordingly.
The general thumb of rule is that you should never use *_general_ci collation anymore. MySQL is using utf8mb4_0900_ai_ci as default.
But what does “utf8mb4_0900_ai_ci” mean?
utf8mb4 means that each character is stored as a maximum of 4 bytes in the UTF-8 encoding scheme.
0900 refers to the Unicode Collation Algorithm version. (The Unicode Collation Algorithm is the method used to compare two Unicode strings that conforms to the requirements of the Unicode Standard).
ai refers accent insensitivity. That is, there is no difference between e, è, é, ê and ë when sorting.
ci refers to case insensitivity. This is, there is no difference between p and P when sorting.
But … MariaDB does not support utf8mb4_0900_ai_ci. So what to use?
The answer is: It depends
Here is a quick summary table:
Compatibility
UCA
Preferred collation
Problems
MySQL
9.0
utf8mb4_0900_ai_ci
None
MariaDB
9.0
uca1400_as_ci
None
Both
5.2
utf8mb4_unicode_520_ci
Mother-daddy
Here is a summary table versions you should not use:
Collation
Does not support
utf8_* utf8mb3
– no support for Emoji in supplementary multi-lingual plane (SMP) – Additional Chinese characters (CJK Unified Ideographs Extension B) in Supplementary ideographic plane (SIP)
If you cannot connect to a MySQL server via SSH in MySQL Workbench, you should take into account that MySQL workbench cannot use OPEN SSH keys but only RSA keys. So a common cause is that the key you have is in OpenSSH format.
You can convert OpenSSH keys to RSA. The following command will do the conversion for you but keep in mind that it will overwrite the existing key so you should take a backup if you still needed.
This is an incompatibility (assuming the database model is correct) between MySQL workbench and MySQL Server. For example, this could occur occasionally by installing XAMPP 3.2.2 and latest MySQL Workbench 8.
You must be logged in to post a comment.