Installation and basic operation of Mysql database


basic operation

1. Mysql database installation and environment configuration

1. Database download

Mysql download address
insert image description here
insert image description here
Click to download and decompress,
remember the decompression address

2. Environment configuration

insert image description here
insert image description here
insert image description here
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
insert image description here
, 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
insert image description here
and enter the bin directory of the installation
insert image description here

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 mysqlto 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

  1. database login
mysql -u root -p
  1. View all current databases
show databases;
  1. create a database
create database 数据库名 DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
create database 数据库名 DEFAULT CHARSET 编码 COLLATE 排序规则
  1. drop a database
drop database 数据库名;
  1. enter the database
use 数据库名;
  1. View all tables under the database
show tables

table operation

  1. 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

  1. delete table
drop table 表名 ;
  1. empty table
delete from 表名;
truncate table 表名;(速度快,无法回滚撤销等)
  1. modify table

    1. add column
    alter table 表名 add 列名 类型
    alter table 表名 add 列名 类型 default 默认值;
    alter table 表名 add 列名 类型 not null default 默认值;
    alter table 表名 add 列名 类型 not null primary key auto_increment
    
    1. delete column
    alter table 表名 drop column 列名;
    
    1. modify column
    alter table 表名 modify column 列名 类型;
    alter table 表名 change 原列名 新列名 新类型;
    alter table 表名 alter 列名 set default 1000;
    

Guess you like

Origin blog.csdn.net/Tom197/article/details/119642119