Mysql 数据库名称限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9537771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:20:44  来源:igfitidea点击:

Mysql Database Name Restrictions

mysqldatabase

提问by nvlbg

I am building a system where while the admin is installing it, one of the steps is to create a database (from the system). So my question is, how should I validate the database name? I found it can't be longer than 64 chars but is this the only restriction? I tested some db names with special characters in phpmyadmin which didn't give an error.

我正在构建一个系统,当管理员安装它时,其中一个步骤是创建一个数据库(从系统)。所以我的问题是,我应该如何验证数据库名称?我发现它不能超过 64 个字符,但这是唯一的限制吗?我在 phpmyadmin 中测试了一些带有特殊字符的数据库名称,但没有出现错误。

回答by

MySQL database naming restrictions:

MySQL 数据库命名限制:

  • Cannot be longer than 64 characters.
  • Cannot contain /\or .characters.
  • Cannot contain characters that are not permitted in file names.
  • Cannot end with space characters.
  • 不能超过 64 个字符。
  • 不能包含/\.字符。
  • 不能包含文件名中不允许的字符。
  • 不能以空格字符结尾。

More information here.

更多信息在这里

回答by Ben Vertonghen

The Regex for this:

正则表达式:

^[^\/?%*:|\"<>.]{1,64}$