How to set default collation for mysql xampp, windows - mysql

Hi I ran into this question and could not get an answer. How can you set default, server-wide collation for your MySQL database for XAMPP+Windows.

What I have figured out. Look for my.ini file in your mysql folder, bin subfoler (e.g. E:\xampp\mysql\bin). Backup your my.ini file and open it for edit, then look for following:
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
Here you can change your collation to the desired default value. Save edits and restart MySQL.

Related

error #1238 when updating datetime format variable

I'm attempting to change the MySQL global variable datetime_format to use zulu time (%Y-%m-%dT%H:%i:%sZ) inside my application.
I've never had any issues running this command on localhost before and I cannot find a way to do it without receiving this error:
#1238 - Variable 'datetime_format' is a read only variable
On MAMP Pro I have access to the my.cnf file, but this doesn't let me set any default variables for startup.
Is there a way I can bypass this and/or set default variables when starting up MySQL or will I have to find an alternative local server?
To set datetime format, you need to add it inside your my.cnf file.
In MAMP you need to follow below steps:
Stop servers
Create a my.cnf file in /Applications/MAMP/conf/
Add your content in to my.cnf
Save my.cnf
Start servers

Cannot change server connection collation in phpmyadmin on local WAMP server

Please help here as I could not change the server connection collation from utfmb4_general_ci to utf_general_ci, it keeps on refreshing back to utfmb4 no matter what I select. If I select utf_unicode_ci, it changed to utfmb4_unicode_ci.
It is quite frustrating.
Thanks,
Since this is your local WAMP server you can first change mysql.ini to change the default character set and collation
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
That will allow you to use the desired charset without sending
'set NAMES'
and
'set CHARSET'
with each connection to DB so it will speed up your application.
I would also suggest that you use the MySQL Workbench instead of phpmyadmin: https://www.mysql.com/products/workbench/ or another tool such as Heidi or Toad for managing your server.

Using Chinese characters in mysql table

I'm trying to use Chinese characters in mysql table. On my first try I wrote something like 中文考试 and my table came back with 还有一个考试.
After research, it was suggested that I use the UTF-8 as my character set. I went back to my table and altered the character set with the command
ALTER TABLE posts CONVERT TO CHARACTER SET utf8;
I tried writing Chinese characters again and got the same result - ( 还有一个考试.).
Here is a copy of my table as it exist right now:
How can I get my table to accept Chinese characters?
After research, it was suggested that I use the UTF-8 as my character
set.
You need to make sure your entire chain from the connection, to the database, to the tables is all UTF8 clean. I have a detailed answer to a similar question here.
But in your case, check the actual MySQL server my.cnf file. The following would set the whole chain to UTF-8:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
The my.cnf is the main MySQL configuration file. Depending on your OS it can be located in a few places. For example in Ubuntu 12.04 it can be found here:
/etc/mysql/my.cnf
So figure out where yours is located, open up that file, edit it, restart MySQL & you should be good to go.

Change default sql mode

I am trying to set my Mysql mode using this. It works, but when the server is restarted it defaults back to STRICT_TRANS_TABLE, NO_ENGINE_SUBSTITUTION. How can I make it permanent so it stays this way after a restart.
set global sql_mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,
NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Alter your mysql configuration file. The file is called my.cnf if in windowzzz look for the my.ini
Append the following line to it and restart your mysql engine after
sql-mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,
NO_ENGINE_SUBSTITUTION"

Where to change the value of lower_case_table_names=2 in XAMPP on Windows?

I am using Windows 7 and XAMPP. I am trying to export my database and while in the process the table names are converted to lower case.
I have searched a lot, I know I have to change the value of lower_case_table_names from 0 to 2, but where do I have to change this value, in which file?
Do these steps:
open your MySQL configuration file: [drive]\xampp\mysql\bin\my.ini
look up for: # The MySQL server [mysqld]
add this right below it: lower_case_table_names = 2
save the file and restart MySQL service
From: http://webdev.issimplified.com/2010/03/02/mysql-on-windows-force-table-names-to-lowercase/
On linux I cannot set lower_case_table_names to 2 (it reverts to 0), but I can set it to 1.
Before changing this setting, do a complete dump of all databases, and drop all databases. You won't be able to drop them after setting lower_case_table_names to 1, because any uppercase characters in database or table names will prevent them from being referenced.
Then set lower_case_table_names to 1, restart MySQL, and re-load your data, which will convert everything to lowercase, including any subsequent queries made.
Try adding/editing lower_case_table_names = 2 in my.ini or my.cnf
I have same problem while importing database from linux to Windows.
It lowercases Database name aswell as Tables' name.
Use following steps for same problem:
Open c:\xampp\mysql\bin\my.ini in editor.
look for
# The MySQL server
[mysqld]
3 . Find
lower_case_table_names
and change value to 2
if not avail copy this at the end of this [mysqld] portion.
lower_case_table_names = 2
This will surely work.
Also works in Wampserver.
Click on the Green Wampserver Icon, choose MySql, then my.ini.
This will allow you to open the my.ini file.
Then -
look up for: # The MySQL server [mysqld]
add this right below it: lower_case_table_names = 2
save the file and restart MySQL service
Important Note - add the lower_case_table_names = 2 statement NOT under the [mysql] statement, but under the [mysqld] statement
Reference - http://doc.silverstripe.org/framework/en/installation/windows-wamp
If you have the file my-default.ini rename it to my.ini
ADD following -
look up for: # The MySQL server [mysqld]
add this right below it: lower_case_table_names = 1
In file - /etc/mysql/mysql.conf.d/mysqld.cnf
It's works for me.
Look for a file named my.ini in your hard disk, in my system it's in
c:\program files\mysql\mysql server 5.1
If it's not my.ini it should be my.cnf
On Mysql Server 8.0 Windows os, if you change lower_case_table_names=2 in mysql.ini the server will not start so you have to follow this
1: Backup all data / export to .sql or Dump all data
2: Stop the server from service
3: Delete the data folder from C:\Program Files\ Mysql Server 8.0\Data
4: Open C:\Program Files\ Mysql Server 8.0\my.ini as an administrator using notepad
5: find set lower_case_table_names= 2 if you want camelCase table name
6: open mysql installer and open reconfigure then open ->show advanced and logging option -> Advanced Options -> use second option from the list
7: then everything will be ok