安装MySql及常用操作

2019-04-21  本文已影响0人  青禾tester

环境:win10

参考文档:http://www.runoob.com/mysql/mysql-install.html

1、下载mysql, 放到本地目录

https://dev.mysql.com/downloads/mysql/

2、在本地目录创建my.ini 配置文件

[mysql]

# 设置mysql客户端默认字符集

default-character-set=utf8

[mysqld]

# 设置3306端口

port = 3306

# 设置mysql的安装目录

basedir=C:\\web\\mysql-8.0.11

# 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错

# datadir=C:\\web\\sqldata

# 允许最大连接数

max_connections=20

# 服务端使用的字符集默认为8比特编码的latin1字符集

character-set-server=utf8

# 创建新表时将使用的默认存储引擎

default-storage-engine=INNODB

3、进入bin目录,初始化数据库

λ mysqld --initialize --console

2019-03-28T04:14:02.731761Z 0 [System] [MY-013169] [Server] D:\mysql-8.0.15\bin\mysqld.exe (mysqld 8.0.15) initializing of server in progress as process 15164

2019-03-28T04:14:02.758972Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.

2019-03-28T04:14:18.947313Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 7ue&+55sggkP

2019-03-28T04:14:24.169391Z 0 [System] [MY-013170] [Server] D:\mysql-8.0.15\bin\mysqld.exe (mysqld 8.0.15) initializing of server has completed

4、启动 mysql 服务

mysqld install
net start mysql

5、本机 mysql 数据库操作

//完整命令: mysql -h 主机名 -u 用户名 -p

λ mysql -u root -p

Enter password: ************  //输入初始化时生成的密码7ue&+55sggkP

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 8.0.15

//修改默认密码

mysql>alter user 'root'@'localhost' identified by '123456';

//创建数据库

mysql> create DATABASE firstData;

//查看已有数据库

mysql> show databases;

//选择数据库

mysql> use firstData;

//创建数据表

mysql> CREATE TABLE `env_record` (

    -> `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键id',

    -> `name` varchar(100) NOT NULL DEFAULT '' COMMENT '标题',

    -> PRIMARY KEY (`id`)

    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='环境数据表';

Query OK, 0 rows affected (0.09 sec)

//查看已有数据表

mysql> show tables;

//查看数据表详情

mysql> desc env_record

//插入一条数据

INSERT INTO env_record

    (name)

    VALUES

    ("测试环境");

//插入多条数据

INSERT INTO env_record  (env_name)  VALUES  ("测试环境"),("线上环境");

//修改表 字段 属性:
 例子:`headers` varchar(50) NOT NULL DEFAULT '' COMMENT '请求头',
两种方法:
ALTER TABLE api_case MODIFY headers varchar(2048);
ALTER TABLE api_case CHANGE headers headers varchar(2048);

//查看数据表

select * from env_record;
上一篇下一篇

猜你喜欢

热点阅读