1

At shell command prompt:

mysqladmin -u"username" -p"password" --default-character-set=utf8 CREATE my_db_schema

--default-character-set=utf8 seems to have no effect and I don't understand why.

Database gets created, but character set is latin1 with collation latin1_swedish_ci.

I found this question, which would seem to be the same issue, but even when I tried a non-root user as the selected answer suggested, I get identical behavior:

(I'm using Windows and MariaDB if that makes any difference)


I have tried these mysqladmin.exe clients:

  1. MariaDB 5.3.2 for Win32 (ia32) with default character set latin1 (no .ini)
  2. MySQL 5.0.77 for linux-gnu (i686) with default character set utf8

In both cases, --default-character-set=utf8 or --default-character-set=latin1 do NOT override the MySQL server's .ini/.cnf settings.

Community
  • 1
  • 1
JohnB
  • 18,046
  • 16
  • 98
  • 110

3 Answers3

1

--default-character-set=utf8 seems to have no effect and I don't understand why.

Database gets created, but character set is latin1 with collation latin1_swedish_ci.

This options does not influence the character of a datatabase, table or column when they are created.

The default-character-set is the character set of the connection to the server -- it ensures values you select from the database come through to the client with the correct encoding for display.

Courtney Miles
  • 3,756
  • 3
  • 29
  • 47
1

As a workaround I'd suggest running:

echo "CREATE DATABASE my_db_schema DEFAULT CHARACTER SET utf8" | mysql -uusername -ppassword
James C
  • 14,047
  • 1
  • 34
  • 43
  • I feel dumb, but: `ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"CREATE DATABASE my_db_schema DEFAULT CHARACTER SET utf8"' at line 1` – JohnB Mar 22 '12 at 15:35
  • You're not including the outer double-quotes are you? – James C Mar 22 '12 at 16:00
  • I can't figure out whether you want me to or not based on your last comment. However, I copied your code verbatim. – JohnB Mar 22 '12 at 16:12
  • Could you try bringing up the MySQL console by typing `mysql -uusername -ppassword` and then entering at the prompt `CREATE DATABASE my_db_schema DEFAULT CHARACTER SET utf8;` and see if you still get the same error message? – James C Mar 22 '12 at 16:56
  • On Windows, your last comment about using the MySQL console to type: `CREATE DATABASE my_db_schema DEFAULT CHARACTER SET utf8;` worked, but your original command line does *NOT* work on Windows. However, it does work perfectly on Unix, but I still don't have a command line work around for Windows. – JohnB Mar 23 '12 at 19:56
  • Try removing the quotes completely with Windoze and see how that works. From my tests with WINE it seems to work OK. – James C Mar 24 '12 at 11:13
  • There is no need to use pipes. MySQL command line client supports `-e` switch, which I believe stands for 'expression', which is in fact just a command. So , you can pass your command like this `mysql -uuser -ppassword -e "CREATE DATABASE my_db_schema DEFAULT CHARACTER SET utf8"` – Vladislav Vaintroub May 08 '12 at 00:19
  • @VladislavVaintroub I tend to use pipes out of habit as fairly often the contents of a query on the commandline are derived from other shell tools (xargs, etc) – James C May 13 '12 at 08:53
  • @JamesC, I understand, yet the original JohnB's question was not about how you use MySQL on Linux. He needed a working solution for his problem. – Vladislav Vaintroub May 14 '12 at 09:23
0

On the surface I'd say this appears to be a mysqladmin bug. I would let the MariaDB devs know about it.

http://kb.askmonty.org/en/reporting-bugs has general instructions about reporting bugs (ignore the bit about using the mysqlbug script, since it is not available on Windows).

P.S. And if the bug exists in MariaDB it likely also exists in MySQL.