简体   繁体   English

在mysql上运行常见的“alter table”命令会返回“no database selected”错误

[英]Running common “alter table” command on mysql returns “no database selected” error

I'm trying to fix some Wordpress character encoding problems by going through and altering all tables to use utf8. 我试图通过修改所有表来修复一些Wordpress字符编码问题以使用utf8。 But the command I'm using doesn't work. 但我正在使用的命令不起作用。

The command: 命令:

ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

The error: 错误:

ERROR 1046 (3D000): No database selected 错误1046(3D000):未选择数据库

This seems to work for everyone. 这似乎适合每个人。 What am I doing wrong? 我究竟做错了什么?

you need to specify the database that contains the table you are altering. 您需要指定包含要更改的表的数据库。 you can do this in two ways: 你可以用两种方式做到这一点:

1) 1)

run this command before your alter table commang: 在alter table commang之前运行此命令:

USE `database_name`;
ALTER TABLE `tbl_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

or 2) 或2)

ALTER TABLE `database_name`.`tbl_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM