How to add a database in mysql
In mysql, you can use the "CREATE DATABASE" statement to add a database. The syntax is "CREATE DATABASE [IF NOT EXISTS] library name [CHARACTER SET character set name] [COLLATE proofreading rule name];".
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
In mysql, you can add a database by using the "CREATE DATABASE" statement to create a new database.
The syntax format for creating a database is as follows:
CREATE DATABASE [IF NOT EXISTS] <数据库名> [[DEFAULT] CHARACTER SET <字符集名>] [[DEFAULT] COLLATE <校对规则名>];
[ ] The content in
is optional. The syntax is as follows:
#Database name:
The name of the created database. The data storage area of MySQL will represent the MySQL database in a directory format, so the database name must comply with the folder naming rules of the operating system, cannot start with a number, and should be as meaningful as possible. Note that MySQL is not case sensitive.IF NOT EXISTS
: Make a judgment before creating the database. The operation can only be performed if the database does not currently exist. This option can be used to avoid duplicate creation errors when 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 creating the database, the system's default character set is used.[DEFAULT] COLLATE
: Specifies the default collation rule for the character set.
MySQL's character set (CHARACTER) and collation rules (COLLATION) are two different concepts. Character sets are used to define how MySQL stores strings, and collation rules define how to compare strings. We will explain MySQL's character set and collation rules separately later.
For example, to create a database named mytestdb, you can execute the CREATE DATABASE statement followed by the database name: mytestdb
, if there is no database in the current MySQL server: mytestdb
, then the creation is successful, as shown below:
CREATE DATABASE IF NOT EXISTS mytestdb;
After executing this statement, MySQL returns a message to notify whether the new database has been successfully created.
SHOW DATABASES
SHOW DATABASES
statement displays all databases in the MySQL database server. You can use the SHOW DATABASES
statement to view the database you want to create, or to view all databases on the database server before creating a new database, for example:
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | testdb | | mytestdb | +--------------------+ 5 rows in set
In this MySQL database server there are 6 databases. information_schema
, performance_schema
and mysql
are the default databases available when we install MySQL, while mytestdb
and testdb
are New database created. Selecting the Database to Use Before using a specified database, you must tell MySQL which database to use by using the USE statement.
USE database_name;
You can use the USE statement to select the sample database (mytestdb) as follows:
USE mytestdb;
From now on, all operations (such as querying data, creating new tables, or calling stored procedures) Will have an impact on the current database (i.e. mytestdb).
[Related recommendations: mysql video tutorial]
The above is the detailed content of How to add a database in mysql. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.
