MySQL dump file and commented out lines

我与影子孤独终老i 提交于 2019-12-19 05:06:07

问题


I have these lines at the top of a MySQL .sql file (dumped with phpMyAdmin):

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

But they all seem to be commented out. So will MySQL ignore them when the file is loaded back into a database? If so, why generate these lines at all?


回答1:


These are conditional comments aimed at certain versions of mySQL.

From here and here:

  • MySQL version specific comments start with /*!
  • And end with */
  • Version numbers are always 5 digits
  • Version numbers are in the format major release number, minor release number, revision number with the major being 1 digit and the minor and revision being 2 digits left-padded with 0’s
  • Version specific comments will target any version equal to or higher than the version number listed



回答2:


MySQL will parse and execute these lines of code, I believe for localization and character-encoding stuff, because the comments start with /*! (with the exclamation mark) instead of just the C-style /*.

Think of it the same way you do conditional comments and Internet Explorer. <!--[if IE]><![endif]--> looks like any plain old HTML comment to other browsers, but IE recognizes this special comment and parses it as needed. Likewise, /*! */ looks like any other comment to other SQL DBMSes but is special to MySQL.



来源:https://stackoverflow.com/questions/3257115/mysql-dump-file-and-commented-out-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!