Home >Database >Mysql Tutorial >How to create a database
Data is the basic operation of learning programming. Here is an introduction to how to create a database with mysql.
Recommended tutorial: MySQL introductory video tutorial
Prerequisite: The computer has the mysql service installed . If you don’t know how to install the mysql service, you can refer to https://www.php.cn/mysql-tutorials-362227.html
1. Log in to the database
Code:
mysql -u root -p
Enter password
2. Create database
Code:
create database test;
3. Use the database just created
Code:
use test;
4. Create a table
Code:
create table user(id int not null,username varchar(100) not null,password varchar(100) not null,primary key(id));
##5. Add a piece of data to the table
insert into user(id,username,password) values(1,'zhang','123');
6. Query data
Code:select * from user;
The above is the detailed content of How to create a database. For more information, please follow other related articles on the PHP Chinese website!