Article directory
basic operation
1. Mysql database installation and environment configuration
1. Database download
Mysql download address
Click to download and decompress,
remember the decompression address
2. Environment configuration
Create a new input path to the bin directory after decompression in path
3. Configure the my.ini file
Find the decompression directory and create a new my.ini file
, enter the following content to save
[mysqld]
#端口号
port = 3306
#mysql-5.7.27-winx64的路径
basedir=E:\Program Files\Mysql\mysql-5.7.27-winx64
#mysql-5.7.27-winx64的路径+\data
datadir=E:\Program Files\Mysql\mysql-5.7.27-winx64\data
#最大连接数
max_connections=200
#编码
character-set-server=utf8
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]
#编码
default-character-set=utf8
4. Install mysql database
Enter cmd to run as an administrator
and enter the bin directory of the installation
Enter mysqld -install
the installation is successful
Enter to net start mysql
start the database
Enter the command mysql -u root -p
, do not need to enter a password, just press Enter Enter
the command line use mysql
to enter the database
Enter the command line update user set authentication_string=password("xxxxxx") where user="root";
xxxxxx is the new password you set,
and the installation operation is complete at this step
2. Common operations of Mysql database
library operation
- database login
mysql -u root -p
- View all current databases
show databases;
- create a database
create database 数据库名 DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
create database 数据库名 DEFAULT CHARSET 编码 COLLATE 排序规则
- drop a database
drop database 数据库名;
- enter the database
use 数据库名;
- View all tables under the database
show tables
table operation
- create a table
create table text(表名)(
id(属性名) int not null auto_increment primary key , --不允许为空&主键&自增
name varchar(16) not null , --不允许为空
email varchar(32) null, --不允许为空(默认)
age int default 3 --插入数据时,如果不给age列设置值,默认值为3
) default charset=utf8;
Note: There can only be one auto-increment column in a table, which is generally the primary key
- delete table
drop table 表名 ;
- empty table
delete from 表名;
truncate table 表名;(速度快,无法回滚撤销等)
-
modify table
- add column
alter table 表名 add 列名 类型 alter table 表名 add 列名 类型 default 默认值; alter table 表名 add 列名 类型 not null default 默认值; alter table 表名 add 列名 类型 not null primary key auto_increment
- delete column
alter table 表名 drop column 列名;
- modify column
alter table 表名 modify column 列名 类型; alter table 表名 change 原列名 新列名 新类型; alter table 表名 alter 列名 set default 1000;