One: Open the command line to start the mysql service
注意事项:应该使用管理员身份打开命令行键入命令"net start mysql"(鼠标右键使用管理员身份打开),否则会出现拒绝访问报错,如下:
After successful startup, as shown in the figure:
When starting as administrator, the directory is "C:\Windows\system32>"
Two: log in to the database
The login command is "mysql -u root -p" and then enter the correct password to enter. If it is installed for the first time, just press Enter to enter.
As shown in the figure:
Three: create a database
1. Type "create datebase library name" to create a database. Don't forget the semicolon at the end of the statement. If you forget the semicolon, just type the semicolon on the next line.
As shown in the figure:
2. After successful creation, type "show databases;" to view all databases, pay attention to databases instead of databases!!
As shown in the figure:
Sometimes in order to prevent garbled characters in the database, set the character set when creating the database, type the command "create datebase ii character set gbk;"
as the picture shows:
3. To use the specified database, type "use ii;"
The effect is as shown in the figure:
4. View the currently used database, type "select database();"
The effect is as shown in the figure:
5, add a table in the current database, type
copy code
create table 表名(
//列名 字符格式 约束
//注意末尾加逗号,最后一列末尾除外
uid int(32) primary,
uname varchar(32) ,
upassword varchar(32)
);
After copying the code
, the effect after building the table is as follows:
6. View the table structure
//desc table name
desc user;
As shown in the figure:
7. Add table columns
//alter table table name add field character format constraints
alter table user add unifo varchar(32) not null;
8. Modify table columns
alter table 表名 modify 列名 字符格式 约束
9. Modify the table name
alter table 表名 change 旧列名 新列名 新字符格式 新约束
10. Rename
rename table 旧表名 to 新表名