In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor to share with you is a simple creation of database sql statement analysis, I believe many people do not understand, in order to let you better understand, so give you a summary of the following, let's look down. I'm sure you'll get something.
The sql statement that creates the database is "CREATE DATABASE" and the syntax is "CREATE DATABASE database name [[DEFAULT] CHARACTER SET character set name] [[DEFAULT] COLLATE proofreading rule name];".
In MySQL, you can use CREATE DATABASE statements to create a database in the following syntax format:
CREATE DATABASE [IF NOT EXISTS] [[DEFAULT] CHARACTER SET] [[DEFAULT] COLLATE]
The content in [] is optional. The syntax is as follows:
Create the name of the database The datastore of MySQL will represent the MySQL database in a directory manner, so the database name must conform to the operating system's folder naming rules, cannot start with a number, and should be as meaningful as possible. Note that there is no case sensitivity in MySQL.
IF NOT EXISTS: make a decision before creating a database, and the operation can only be performed if the database does not currently exist. This option can be used to avoid errors that are created repeatedly because the database already exists.
[DEFAULT] CHARACTER SET: specifies the character set of the database. The purpose of specifying the character set is to avoid garbled data stored in the database. If you do not specify a character set when you create the database, the default character set of the system is used.
[DEFAULT] COLLATE: specifies the default proofreading rules for the character set.
MySQL's character set (CHARACTER) and proofreading rules (COLLATION) are two different concepts. Character sets are used to define how MySQL stores strings, and proofreading rules define how strings are compared. Later, we will explain the character set and proofreading rules of MySQL separately.
Example 1: the simplest statement to create a MySQL database
Create a database called test_db in MySQL. Enter the SQL statement CREATE DATABASE test_db; in the MySQL command line client to create a database
Mysql > CREATE DATABASE test_db;Query OK, 1 row affected (0.12 sec)
Example 2: specify character set and proofreading rules when creating MySQL database
Use the MySQL command line tool to create a test database named test_db_char with a default character set of utf8 and a default proofreading rule of utf8_chinese_ci (simplified Chinese, case-insensitive)
Mysql > CREATE DATABASE IF NOT EXISTS test_db_char-> DEFAULT CHARACTER SET utf8-> DEFAULT COLLATE utf8_chinese_ci;Query OK, 1 row affected (0.03 sec)
At this point, you can use SHOW CREATE DATABASE to view the definition declaration of the test_db_char database and find that the specified character set of the database is utf8, and the running result is as follows:
Mysql > SHOW CREATE DATABASE test_db_char +-+-+ | Database | Create Database | +-+- -+ | test_db_char | CREATE DATABASE `test_db_ char` / *! 40100 DEFAULT CHARACTER SET utf8 * / | +-- -+ 1 row in set (0.00 sec) so much for the simple sql statement analysis of creating a database. I hope that the above content can have a certain reference value for everyone, and can be put into practice. If you like this article, you might as well share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.