A script to change all tables and fields to the utf-8-bin collation in MYSQL(在MYSQL中将所有表和字段更改为utf-8-bin排序规则的脚本)
问题描述
是否有我可以运行的 SQL
或 PHP
脚本来更改数据库中所有表和字段中的默认排序规则?
Is there a SQL
or PHP
script that I can run that will change the default collation in all tables and fields in a database?
我可以自己写一个,但我认为这应该在这样的网站上很容易获得.如果我能在有人发布之前自己想出一个,我会自己发布.
I can write one myself, but I think that this should be something that readily available at a site like this. If I can come up with one myself before somebody posts one, I will post it myself.
推荐答案
小心!如果您确实将 utf 存储为另一种编码,那么您的手上可能会一团糟.先备份.然后尝试一些标准方法:
Be careful! If you actually have utf stored as another encoding, you could have a real mess on your hands. Back up first. Then try some of the standard methods:
例如http://www.cesspit.net/drupal/node/898http://www.hackszine.com/blog/archive/2007/05/mysql_database_migration_latin.html
我不得不将所有文本字段转换为二进制,然后再转换回 varchar/text.这救了我的屁股.
I've had to resort to converting all text fields to binary, then back to varchar/text. This has saved my ass.
我的数据是UTF8,存储为latin1.我做了什么:
I had data is UTF8, stored as latin1. What I did:
删除索引.将字段转换为二进制.转换为utf8-general ci
Drop indexes. Convert fields to binary. Convert to utf8-general ci
如果你在 LAMP 上,不要忘记在与数据库交互之前添加 set NAMES 命令,并确保你设置了字符编码头.
If your on LAMP, don’t forget to add set NAMES command before interacting with the db, and make sure you set character encoding headers.
这篇关于在MYSQL中将所有表和字段更改为utf-8-bin排序规则的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在MYSQL中将所有表和字段更改为utf-8-bin排序规则的脚本
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01