How can I change my MySQL collation in WAMPSERVER - mysql

How can I change my MySQL collation in WAMPSERVER from latin1_swedish_ci to UTF-8 because I think my HTML special characters are getting all messed up

put in your C:\wamp\bin\mysql\mysql5.5.24\my.ini:
character-set-server=utf8
collation-server=utf8_general_ci

You could use
set names 'utf8'
each time you open a connection.
Or add the following line to your my.ini file and restart your server.
default-character-set=utf8
If you've already got tables set up you'll need to alter them too you can alter them with:
ALTER TABLE tablename COLLATE utf8_general_ci
etc or pop into phpmyadmin and do it there. Remember if you alter database collation it'll only affect new tables created after that not pre-existing ones in that database already, so you will need to alter them also.

Related

mysql_install_db wrong charset and collation

I am creating a new server with the mysql_install_db tool. It sets the correct datadir, port, password, service etc. But My problem is that the charset and collation of my base tables are wrong. They need to be utf8mb4 and utf8mb4_general_ci.
I can't find a way to change these tables with the installation. When I change my.cnf/my.ini it only changes for newly created databases. But Since mysql_install_db creates the system databases, they are created wrong.
It also looks like my msyql_install_db.exe does not accept a defaults-file argument.
Something else is also weird. If I run the command to create a new database, it will also use utf8mb3 while I explicitly set the COLLATE to utf8mb4_unicode_ci.
CREATE DATABASE IF NOT EXISTS tt DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
I am using mariadb 10.6.4 which is the latest version.
Anyone knows how to setup the correct charset and collation to the system databases?
Tools\mariadb-winx64\bin\mysql_install_db.exe --datadir="Tools\mariadb-data" --password=PASSWORD --port=8137 --service=MyDB
[Update]
I tried to setup my.cnf with the following, but seems to take no effect: Change MySQL default character set to UTF-8 in my.cnf?
Also tried using a different way with initializing-insecure, but also the same results. I created a my.cnf with the correct encoding, but still got the wrong table encoding:
mariadb-winx64\bin\mariadbd.exe --defaults-file=./my.cnf --initialize-insecure --datadir=./Test
And my.cnf
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
skip-grant-tables
port = 5137
collation-server = utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4

Set default collation for create database

I'm trying to set the default-default characterset for a new created mysql database. Because I'm lazy, I will use "CREATE DATABASE blahblah;" without providing additional "CHARSET" or "DEFAULT COLLATE". After "SHOW CREATE DATABASE blahblah;" I see:
blahblah | CREATE DATABASE `blahblah` /*!40100 DEFAULT CHARACTER SET latin1 */
Latin1? I need utf8. Let's change my.cnf and mysqld.cnf.
mysqld.conf (server config) is
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
.my.cnf (my local file) is
[client]
default-character-set=utf8
Just to by sure, let's restart the server, drop the database, create and... again latin1.
To be honest, I also tried character_set_server (underscores, instead of dashes), copy the entries to .my.conf back and forth... and there is still the f***g latin1.
So... did I made a typo? Do I miss any extra line somewhere? Is it impossible to set a default-default charset, so I need to provide them everytime I do a "create database..."?
Ubuntu 18.04.2, mysqld 5.7.26-0ubuntu0.18.04.1
(I am aware of the Change default collation/character set, but it doesnt work)

How to change all fields in database from latin1_swedish_ci to utf8_general_ci?

The title saiz it all, right? :)
Details:
I'm looking for a SQL query I can use in phpmyadmin. Need to Change all my fields in one database from latin1_swedish_ci to utf8_general_ci
The main problem in your case is when you change the collation/character set from the table the data inside the table are latin1 and the table is utf8 until then.
What you can try is to make a dump of the table with the old character set.
mysqldump -uuser -p --default-character-set=latin1 dbname > dump.sql
and then import the database with the new character set like this:
mysql -uuser -p --default-character-set=utf8 dbname_test < dump.sql
To test i would import the dump to a test database. If the characters are not correct after the import. Use an Editor like pspad or notepad++ and change the file encoding to UTF-8. After this you can try to import another time.
The most times encodings are very annoying but i hope you can solve it.
When you only have phpmyadmin use the "Export" function and make the same with phpmyadmin. Export in the actual encoding and try to import in the new encoding but then you have to change the file encoding i think.
Change the default collation to utf8_general_ci in MySql:
Open the my.ini file. (C:\xampp\mysql\bin\my.ini)
Find the text [mysqld] and add the below lines.
[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
The above two lines will select a character set and collation at server startup. These settings apply server-wide and apply as the defaults for databases created by any application, and for tables created in those databases.

mysql utf-8 support

when I create a new table, it always is 'latin-swedish-ci' by default. my goal is that this table can store utf-8 text. I tried this way, give me error .
cd C:\mysql-5.5.14-winx64\bin
mysqld --standalone --console --default-storage-engine=InnoDB --default-character-set=utf8
[ERROR] mysqld: unknown variable 'default-character-set=utf8'
Your Database probably has the default charset on latin1 and default collation set to latin1-swedish-ci and so altering the table should help
http://dev.mysql.com/doc/refman/5.1/en/alter-database.html
ALTER DATABASE `MyDatabaseName`
CHARACTER SET utf8
COLLATE utf8_general_ci;
You can always specify column encodings/collations within CREATE TABLE statement. This has additional benefit of making your data structure more portable in case you ever need to move it to another server.

Can not insert UTF8 to Database MySQL in Linux

When create table, I have setted charset = utf8.
I create 1 store procedure to insert data to database.
When insert data UTF8 to Database on Window, it works OK.(Display data correctly)
But it doesnot work in Linux.(Display data not correctly)
The strange thing is insert UTF8 work fine in window, but when i deploy MySQL in linux, when insert data to database it insert wrong UTF8 value.
Thanks for help
Edit: Update more detail follow comment of #Col. Shrapnel
You should start mysql console with --default-character-set=utf8:
mysql --default-character-set=utf8 -uyour_user -p
most probably you didn't specify client character set by issuing SET NAMES UTF8 query
but there can be other problems - your database or a web page may be not in the utf-8
I just found a solution for my problem: Edit file my.cnf under /etc/my.cnf as below:
[mysqld]
default-character-set=utf8
default-collation=utf8_general_ci
character-set-server=utf8
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'
[client]
default-character-set=utf8
But i still confuse why this bug occur in Linux, not in Window.