MySQL学习笔记(一)

174 阅读4分钟

小知识,大挑战!本文正在参与“程序员必备小知识”创作活动。

MySQL


一、数据库概述

1、 概述

  • 数据库:Database , 简称DB。是指按照一定格式存储数据的一些文件的组合(数据仓库)

  • 数据库管理系统:DataBaseManagement , 简称DBMS,用来管理数据库中的数据的。可以对其中的数据进行增删改查。

    • 常见的数据库管理系统:MySQL 、 Oracle、MS SqlSever 、 DB2 、sybase等
  • SQL:是一种结构化查询语言通过编写SQL语句,由DBMS负责执行SQL语句,最终来完成数据库中数据的增删改查(相当于编程语言)

  • 关系:DBMS -----》 通过执行SQL语句操作数据库中的数据

  • CRUD : 增删改查,对应 create 、retrave(查,检索)、update 、 delete ;

2、 安装MySQL

  • 免安装版:

    • 第一步:去官网下载安装
    • (重点)第二步:先解压,然后在mysql下创建一个my.ini文件, 更改my.ini文件里面的两行安装目录, 第二行加上\data,my.ini文件不能多或少一个符号, 在path(环境变量里面)加上mysql路径(/bin)。
    • (重点)第三步:进入命令指示符(cmd), 输入mysqld --initialize-insecure --user=mysql, 再输入mysqld -install, 出现Service successfully installed.表示配置完成 启动数据库net start mysql, 输入mysql -u root -p,不用输入密码直接回车 出现mysql>表示配置完成 输入alter user user() identified by "密码"; 输入net stop mysql关闭数据库
  • 安装版(msi):

    • 注意事项

      • 1、端口号:是任何一个软件都会有的,端口号是一个软件的唯一代表。通常和ip地址在一起。ip地址用来定位计算机,port端口号是用来定位计算机上的服务/应用的。在同一台计算机上,端口号不能重复,具有唯一性。 MySQL占用的默认端口号3306
      • 2、字符集(字符编码方式):设置MySQL的字符编码方式为UTF - 8
      • 3、服务名称:默认是MySQL
      • 4、环境变量path
      • 5、MySQL超级管理员root名称不变,设置密码
      • 6、设计密码的同时,可以激活root账户远程访问。激活后,root账户可以从外地登录访问;不激活则表示root账户只能在本地使用

3、 MySQL的卸载

  • 免安装版:

    • 第一步:停止mysql服务 net stop mysql

    • 第二步:卸载mysql

    • 第三步:删除mysql服务 sc delete mysql(服务名称)

      • 如果服务删除不了,就从注册表删除 win+R:regedit打开注册表 HEKY_LOCAL_MACHINE-SYSTEM-CurrentControlSet-Service 找到mysql服务删除即可
    • 第四步:环境变量删除

  • 安装版(msi):

    • 第一步:双击安装包卸载
    • 第二步:删除目录(表层位置,C盘的ProgramDate文件下的MySQL目录一起删掉)
    • 第三步:环境变量删除

4、计算机中MySQL的服务

  • 流程:计算机右键 --- 管理 --- 服务和应用程序 --- 服务 --- 找MySQL服务
  • MySQL的服务默认为启动, 默认为自动启动,表示启动操作系统的时候自动启动

Windows 系统中的启动方式

 net start MySQL                         // 启动MySQL服务
 net stop MySQL                          // 关闭MySQL服务

5、如何登录MySQL服务(客户端)

使用bin目录下的mysql.exe命令来连接mysql数据库服务器

  • 第一步:启动MySQL服务

  • 第二步:mysql -u 用户名称 -p密码 (其中的-u 表示user , -p表示passward)

    • 本地登录(显示密码的形式)

       C:\Users\张中宇>mysql -u root -p20zzy100588A
       mysql: [Warning] Using a password on the command line interface can be insecure.
       Welcome to the MySQL monitor.  Commands end with ; or \g.
       Your MySQL connection id is 8
       Server version: 8.0.18 MySQL Community Server - GPL
       ​
       Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
       ​
       Oracle is a registered trademark of Oracle Corporation and/or its
       affiliates. Other names may be trademarks of their respective
       owners.
       ​
       Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
       ​
       mysql>
      
    • 本地登录(隐藏密码的形式)

       C:\Users\张中宇>mysql -u root -p
       Enter password: ************
       Welcome to the MySQL monitor.  Commands end with ; or \g.
       Your MySQL connection id is 10
       Server version: 8.0.18 MySQL Community Server - GPL
       ​
       Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
       ​
       Oracle is a registered trademark of Oracle Corporation and/or its
       affiliates. Other names may be trademarks of their respective
       owners.
       ​
       Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
       ​
       mysql>
      

\