Create database (MySQL): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
Regel 26: Regel 26:
 
* Appearantly, <code>CREATE DATABASE</code> is a ''statement''. I'm always confused if you would call this a ''command'', ''keyword'', ''function'', or whatever. Glad to have this solved
 
* Appearantly, <code>CREATE DATABASE</code> is a ''statement''. I'm always confused if you would call this a ''command'', ''keyword'', ''function'', or whatever. Glad to have this solved
 
* The keywords ''database'' and ''schema'' are identical. Personally, I prefer the term ''database'', as you can see in the example above
 
* The keywords ''database'' and ''schema'' are identical. Personally, I prefer the term ''database'', as you can see in the example above
* It's unclear from the syntaxis above, if there are actually only two <code>create_options</code>, or more.
+
* It's unclear for me from the syntaxis above, if there are actually only two <code>create_options</code>, or more.
* Each create_option specifies a database characteristic. Database characteristics are stored in the db.opt file in the database directory. The CHARACTER SET option specifies the default database character set. The COLLATE option specifies the default database collation [[https://dev.mysql.com/doc/refman/5.7/en/create-database.html]
+
* Each <code>create_option</code> specifies a database characteristic. Database characteristics are stored in the <code>db.opt</code> file in the database directory. The CHARACTER SET option specifies the default database character set. The COLLATE option specifies the default database collation [https://dev.mysql.com/doc/refman/5.7/en/create-database.html]
 +
* To see the available character sets and collations, use the SHOW CHARACTER SET and SHOW COLLATION statements
 +
* A database in MySQL is implemented as a directory containing files that correspond to tables in the database. Because there are no tables in a database when it is initially created, the CREATE DATABASE statement creates only a directory under the MySQL data directory and the db.opt file
 +
* See [https://dev.mysql.com/doc/refman/5.7/en/identifiers.html] for rules concerning permissible database names. If a database name contains special characters, the name for the database directory contains encoded versions of those characters as described [https://dev.mysql.com/doc/refman/5.7/en/identifier-mapping.html here]
 +
* If you manually create a directory under the data directory (for example, with <code>mkdir</code>), the server considers it a database directory and it shows up in the output of SHOW DATABASES
 +
* When you create a database, let the server manage the directory and the files in it. Manipulating database directories and files directly can cause inconsistencies and unexpected results
 +
* MySQL has no limit on the number of databases. The underlying file system may have a limit on the number of directories.
 +
* You can also use the <code>mysqladmin</code> program to create databases.
  
 
== Bronnen ==
 
== Bronnen ==

Versie van 20 jun 2020 17:51

Wat ik meestal zoek (collate is hier niet gespecificeerd → Default):

create database
   bb_wp
default character set
   utf8

Syntaxis

Just for fun, let's have a look at the complete syntaxis. According to [1], this would be something like:

CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
   [create option] [create_option] ... [create_option]

   create_option:
   {
      [DEFAULT] [CHARACTER SET [=] charset_name
      |
      [DEFAULT] COLLATE [=] collation_name
   }
  • Appearantly, CREATE DATABASE is a statement. I'm always confused if you would call this a command, keyword, function, or whatever. Glad to have this solved
  • The keywords database and schema are identical. Personally, I prefer the term database, as you can see in the example above
  • It's unclear for me from the syntaxis above, if there are actually only two create_options, or more.
  • Each create_option specifies a database characteristic. Database characteristics are stored in the db.opt file in the database directory. The CHARACTER SET option specifies the default database character set. The COLLATE option specifies the default database collation [2]
  • To see the available character sets and collations, use the SHOW CHARACTER SET and SHOW COLLATION statements
  • A database in MySQL is implemented as a directory containing files that correspond to tables in the database. Because there are no tables in a database when it is initially created, the CREATE DATABASE statement creates only a directory under the MySQL data directory and the db.opt file
  • See [3] for rules concerning permissible database names. If a database name contains special characters, the name for the database directory contains encoded versions of those characters as described here
  • If you manually create a directory under the data directory (for example, with mkdir), the server considers it a database directory and it shows up in the output of SHOW DATABASES
  • When you create a database, let the server manage the directory and the files in it. Manipulating database directories and files directly can cause inconsistencies and unexpected results
  • MySQL has no limit on the number of databases. The underlying file system may have a limit on the number of directories.
  • You can also use the mysqladmin program to create databases.

Bronnen