I need to convert a MyISAM latin 1 DB into a MyISAM utf8 db
following another question I exported my DB without any encoding specification
mysqldump -uroot -p --skip-opt --set-charset --skip-set-charset mydb > mydb_utf8.sql
changed my DB to default charset utf8
now I need to specify on import that i want MyISAM tables ( default setting is InnoDB )
mysql -uroot -p --default-character-set=utf8 --default-storage-engine=MyISAM mydb < mydb_utf8.sql
--default-storage-engine=MyISAM give me this error "mysql: unknown variable 'default-storage-engine=MyISAM'"
--default-storage-engine looks like its a mysqld startup option not a mysql start option..
Open your SQL file with a text editor and on the top
SET default_storage_engine=MyISAM;
Related
I would like to take a dump from Mysql 8.0.11 and restore it into 5.7.27.
When I tried to restore it I got the error:
ERROR 1273 (HY000) at line 25: Unknown collation: 'utf8mb4_0900_ai_ci'
Then I tried to use the compatible flag to make it easier on an older MySQL DB.
mysqldump --compatible=mysql4 --add-drop-table -u r00t -h xxx.eu-north-1.rds.amazonaws.com -p radius_db > ~/radius.sql
But that doesn't seem to work either:
mysqldump: Couldn't execute '/*!40100 SET ##SQL_MODE='MYSQL40' */':
Variable 'sql_mode' can't be set to the value of 'MYSQL40' (1231)
Any advice would be appreciated.
Simply put, use as a DEFAULT "utf8" and as COLLATE "utf8_general_ci".
One way to solve your problem is to change in your import .sql-Files from
"utf8mb4" to "utf8"
and "utf8mb4_0900_ai_ci" (or something else) to "utf8_general_ci"
Hint: Don't forget to backup your files just in case ;-)
Go to your (.sql) import files and do these changes.
From:
ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8_general_ci;
to:
ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
Reimport again.
You can use the next code to move your database from mysql 8.x to mysql 5.x.
mysqldump db > db.sql
sed -i s/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g db.sql
mysql db < db.sql
db is your database name
For a very long time i was suffering form the Latin-1 encoding in My Django web application DB causing this error when trying to select a matching string using LIKE :
-- UnicodeEncodeError:'latin-1' codec can't encode character--
i've tried every solution from setting (charset='utf8') in the connection to applying cursor.execute("set names 'utf8'") before my actual query but nothing seams to work.
Until i came across this blog post: https://www.whitesmith.co/blog/latin1-to-utf8/
about the encoding problem and it is the same problem that i have because when i looked in phpMyAdmin a saw that by default my DB i Latin-1 encoding:
chatbot_brain=>utf8_general_ci
information_schema=>utf8_general_ci
Total: 2=> latin1_swedish_ci
So, the solution is to dump the DB and change the description in the schema file:
# Login into your future database host to create a new database with an UTF-8 charset
$ mysql -h FUTURE_HOST -u FUTURE_USER -p
mysql> CREATE DATABASE `FUTURE_DB` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
# Flush the current database schema on the future host, replacing all CHARSET=latin1 occurrences along the way
mysqldump -h CURRENT_HOST -u CURRENT_USER -p CURRENT_DB --no-data --skip-set-charset --default-character-set=latin1 \
| sed 's/CHARSET=latin1/CHARSET=utf8/g' \
| mysql -h FUTURE_HOST -u FUTURE_USER -p FUTURE_DB --default-character-set=utf8
# Flush the current database data on the future host
mysqldump -h CURRENT_HOST -u CURRENT_USER -p --no-create-db --no-create-info --skip-set-charset --default-character-set=latin1 CURRENT_DB \
| mysql -h FUTURE_HOST -u FUTURE_USER -p FUTURE_DB --default-character-set=utf8
Now i know what is the problem and the solution, But my question is how i can applied to my Django project-- Do i have to use my computer terminal and SSH session or is there any application of that?
this is a sceen shot of my DB in phpmyAdmin:
https://ibb.co/dDu7D5
Thank you
PS(I am using Django10 , Python3.5,Mysql,Webfaction sherd host)
Start with the "best practice" in Trouble with utf8 characters; what I see is not what I stored
Check for improper setup in Python: http://mysql.rjweb.org/doc.php/charcoll#python
Hopefully that 2-step mysqldump will work.
After loading, check some of the data by using "Test the data" in my first link. (SELECT HEX(col)...)
I have exported all databases (localhost.sql) from phpmyadmin. Now I am trying to import all database file (localhost.sql) using command
mysql -u root -p < /localhost.sql
this is showing error as No database selected.
Localhost.sql has all database, i dont have any other backup of databases except localhost.sql file.
Because when you export file into phpMyAdmin there is no database name. If you want it, when you export click "Custom" in the section export method and tick "Add CREATE DATABASE / USE". Or add at the top of your localhost.sql :
CREATE DATABASE IF NOT EXISTS `NameOfYourDataBase` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `NameOfYourDataBase`;
Or the method I use : I export, i drop/delete everything and i recreate a DB with the same name THEN I import the localhost.sql
These information will useful to you.
Only one database backup:
mysqldump -d -h localhost -u root -pmypassword databasename > databasename.sql
or
mysqldump database_name > database_name.sql
Multiple databases can be backed up at the same time:
mysqldump --databases database_one database_two > two_databases.sql
It is also simple to back up all of the databases on a server:
mysqldump --all-databases > all_databases.sql
Thank you..
I'm using mysqldump to dump my database that contains UTF8MB4 columns with UTF8MB4 data. When I import this .sql file into a new database with UTF8MB4 support, all UTF8MB4 characters are converted into ????. Anybody got a clue about how to make MySQL and import work with UTF8MB4?
You should specify the character set with --default-character-set=utf8mb4 option when using mysqldump.
$ mysqldump --default-character-set=utf8mb4 -uusername -p database > dump.sql
Since MySQL 8.0 default charset for mysqldump is utf8mb4, so the problem should not appear anymore.
However in MySQL 5.7 default charset for mysqldump is utf8, so there you should explicitly change it as in Henridv answer (--default-character-set=utf8mb4).
I accidentally replaced all records for a field in a mysql table with NULL and am attempting to restore a backup so I can run an update query between my current table and the backup. I created a new db called db_bckup, left it empty, then tried to import it from the command line:
mysql -u root -p db_bckup < mysqlbackupfile.sql
I assumed this would load the backup to my db_bckup database which was empty. To my surprise, it overwrote my original database rather than loading into db_bckup. In looking at the contents of the sql file, I noted that the contents include lines:
Host: localhost Database: db
-------------------------------------------
Server version 5.5.34-0ubuntu0.13.04.1
[SET a bunch of things]
Current Database: 'db'
CREATE DATABASE /*!32312 IF NOT EXISTS*/ 'db' /*!40100 DEFAULT CHARACTER SET latin1 */;
USE 'db';
[table specific stuff]
I suspect that the references to 'db' in the sql file is overriding my command line import code.
My question is: Is it the sql file or command line that's causing the overwrite? If the sql file is the cause, is it a matter of editing the backup file manually to change the db name to db_bckup or is there a more administrative way to change all the 'db' references within the file to 'db_bckup'? I am a little wary of messing with the backup file, so I'd like to take the best approach those with more experience would recommend.
If you specify db_name when mysqldump, USE db_name will not printed in it's output. I guess that you tried --databases or --all-database
Usage: mysqldump [OPTIONS] database [tables] <= you need to run mysqldump this way
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
and FYI, mysqldump provides option which not create table.
-t, --no-create-info Don't write table creation info.