01 安装教程

1.1 官网下载:https://www.mysql.com/

image.png
2021官网排版,直接拉到最下面
image.png
image.png
image.png

1.2 六个步骤:下载安装

1.双击,32位和64位是相互兼容的
image.png

2.同意协议
image.png

3.选择安装模式,这里是自定义
image.png

4.安装路径,注意一定是非中文无特殊符号的路径!
image.png
5.安装即可
image.png
image.png
6.有两页广告,可跳过
image.png

安装完成!
image.png

1.3 配置环境

1.到这一步仅仅是环境安装好了,还没有配置。

image.png
要是不小心叉掉了配置页面,可以见下图
image.png

2.打开配置程序的实例
image.png
image.png
image.png
image.png
image.png
开发过程通常不选,因为总会有人攻击该端口
image.png
image.png
image.png
image.png
安装完成

image.png

1.4 配置my.ini

  • 可以修改端口
  • 可以修改存储目录

image.png
image.png
配置完千万记得重启一下MySQL服务

1.5 打开MySQL服务

方法一:
image.png
方法二:命令行方式
image.png

  1. 启动:net start mysql服务名
  2. 停止:net stop mysql服务名

02 卸载教程

方法一:常规软件卸载

1.主文件卸载
image.png
2.找到安装路径,删除残留文件
image.png
3.最后,在C盘中会有隐藏文件夹“ProgramData”,里面会有一些数据
image.png

方法二:通过软件卸载

  • 360卸载
  • 软件管家等等

image.png

  • 一般不需要清理注册表,除非卸载后安装还是有问题

03 MySQL服务端的登录和退出

登录 mysql –h 主机名 –u用户名 –p密码
退出 exit

image.png

04 SQL常见命令

  1. show databases 查看所有的数据库
  2. use 库名; 打开指定 的库
  3. show tables ; 显示库中的所有表
  4. show tables from 库名;显示指定库中的所有表
  5. create table 表名(
  6. 字段名 字段类型,
  7. 字段名 字段类型
  8. ); 创建表
  9. desc 表名; 查看指定表的结构
  10. select * from 表名;显示表中的所有数据

05 MySQL的常见命令

  • 不区分大小写
  • 每句话用;或\g结尾
  • 各子句一般分行写
  • 关键字不能缩写也不能分行
  • 用缩进提高语句的可读性
  1. 进入 mysql, 在命令行中输入: mysql –uroot –p#### (其中:####表示密码)
    2. 查看 mysql 中有哪些个数据库: show databases; (2)
    3. 使用一个数据库: use 数据库名称; (3. atguigu)
    4. 新建一个数据库: create database 数据库名 (1. atguigu)
    5. 查看指定的数据库中有哪些数据表: show tables; (4, 6, 9)
    6. 建表: image.png(5)
    7. 查看表的结构:desc 表名 (7)
    8. 删除表: drop table 表名 (8)
    9.查看表中的所有记录: select from 表名;
    10.向表中插入记录:insert into 表名(列名列表) values(列对应的值的列表);
    image.png
    注意:插入 varchar 或 date 型的数据要用 单引号 引起来
    11.修改记录: update 表名 set 列1 = 列1的值, 列2 = 列2的值 where …
    image.png
    12.删除记录: *delete from 表名 where ….

    image.png
    13.查看服务器版本
    方式一:登录到mysql服务端
    select version();
    方式二:没有登录到mysql服务端
    mysql --version
    或者 mysql -v
  1. 1.查看当前所有的数据库
  2. show databases;
  3. 2.打开指定的库
  4. use 库名
  5. 3.查看当前库的所有表
  6. show tables;
  7. 4.查看其它库的所有表
  8. show tables from 库名;
  9. 5.创建表
  10. create table 表名(
  11. 列名 列类型,
  12. 列名 列类型,
  13. 。。。
  14. );
  15. 6.查看表结构
  16. desc 表名;
  17. 7.查看服务器的版本
  18. 方式一:登录到mysql服务端
  19. select version();
  20. 方式二:没有登录到mysql服务端
  21. mysql --version
  22. mysql --V

06 MySQL的语法规范

1.不区分大小写,但建议关键字大写,表名、列名小写
2.每条命令最好用分号结尾
3.每条命令根据需要,可以进行缩进 或换行
4.注释
单行注释:#注释文字
单行注释:— 注释文字
多行注释:/ 注释文字 /

07 图形化界面客户端SQLyog

7.1 安装教程

傻瓜式安装(略)
image.png

7.2 界面

1.连接界面

image.png
image.png

附:SQL常用命令实操

在CMD命令行中启动MySQL,并进行常见命令的练习记录

  1. Microsoft Windows [版本 6.1.7600]
  2. 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
  3. C:\Windows\system32>net stop mysql0815
  4. MySQL0815 服务正在停止.
  5. MySQL0815 服务已成功停止。
  6. C:\Windows\system32>net start mysql0815
  7. MySQL0815 服务正在启动 .
  8. MySQL0815 服务已经启动成功。
  9. C:\Windows\system32>mysql -h localhost -P 3306 -u root -p
  10. Enter password: ****
  11. Welcome to the MySQL monitor. Commands end with ; or \g.
  12. Your MySQL connection id is 2
  13. Server version: 5.5.15 MySQL Community Server (GPL)
  14. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  15. Oracle is a registered trademark of Oracle Corporation and/or its
  16. affiliates. Other names may be trademarks of their respective
  17. owners.
  18. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  19. mysql> exit
  20. Bye
  21. C:\Windows\system32>mysql -h localhost -P 3306 -u root -proot
  22. Welcome to the MySQL monitor. Commands end with ; or \g.
  23. Your MySQL connection id is 3
  24. Server version: 5.5.15 MySQL Community Server (GPL)
  25. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  26. Oracle is a registered trademark of Oracle Corporation and/or its
  27. affiliates. Other names may be trademarks of their respective
  28. owners.
  29. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  30. mysql> exit
  31. Bye
  32. C:\Windows\system32>mysql -u root -proot
  33. Welcome to the MySQL monitor. Commands end with ; or \g.
  34. Your MySQL connection id is 4
  35. Server version: 5.5.15 MySQL Community Server (GPL)
  36. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  37. Oracle is a registered trademark of Oracle Corporation and/or its
  38. affiliates. Other names may be trademarks of their respective
  39. owners.
  40. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  41. mysql> show databases;
  42. +--------------------+
  43. | Database |
  44. +--------------------+
  45. | information_schema |
  46. | mysql |
  47. | performance_schema |
  48. | test |
  49. +--------------------+
  50. 4 rows in set (0.00 sec)
  51. mysql> use test;
  52. Database changed
  53. mysql> show tables;
  54. Empty set (0.00 sec)
  55. mysql> show tables from mysql;
  56. +---------------------------+
  57. | Tables_in_mysql |
  58. +---------------------------+
  59. | columns_priv |
  60. | db |
  61. | event |
  62. | func |
  63. | general_log |
  64. | help_category |
  65. | help_keyword |
  66. | help_relation |
  67. | help_topic |
  68. | host |
  69. | ndb_binlog_index |
  70. | plugin |
  71. | proc |
  72. | procs_priv |
  73. | proxies_priv |
  74. | servers |
  75. | slow_log |
  76. | tables_priv |
  77. | time_zone |
  78. | time_zone_leap_second |
  79. | time_zone_name |
  80. | time_zone_transition |
  81. | time_zone_transition_type |
  82. | user |
  83. +---------------------------+
  84. 24 rows in set (0.00 sec)
  85. mysql> select database();
  86. +------------+
  87. | database() |
  88. +------------+
  89. | test |
  90. +------------+
  91. 1 row in set (0.00 sec)
  92. mysql> create table stuinfo(
  93. -> id int,
  94. -> name varchar(20));
  95. Query OK, 0 rows affected (0.01 sec)
  96. mysql> show tables;
  97. +----------------+
  98. | Tables_in_test |
  99. +----------------+
  100. | stuinfo |
  101. +----------------+
  102. 1 row in set (0.00 sec)
  103. mysql> desc stuinfo;
  104. +-------+-------------+------+-----+---------+-------+
  105. | Field | Type | Null | Key | Default | Extra |
  106. +-------+-------------+------+-----+---------+-------+
  107. | id | int(11) | YES | | NULL | |
  108. | name | varchar(20) | YES | | NULL | |
  109. +-------+-------------+------+-----+---------+-------+
  110. 2 rows in set (0.00 sec)
  111. mysql> select * from stuinfo;
  112. Empty set (0.00 sec)
  113. mysql> insert into stuinfo (id,name) values(1,'john');
  114. Query OK, 1 row affected (0.00 sec)
  115. mysql> insert into stuinfo (id,name) values(2,'rose');
  116. Query OK, 1 row affected (0.00 sec)
  117. mysql> select * from stuinfo;
  118. +------+------+
  119. | id | name |
  120. +------+------+
  121. | 1 | john |
  122. | 2 | rose |
  123. +------+------+
  124. 2 rows in set (0.00 sec)
  125. mysql> update stuinfo set name='lilei' where id=1;
  126. Query OK, 1 row affected (0.00 sec)
  127. Rows matched: 1 Changed: 1 Warnings: 0
  128. mysql> select * from stuinfo;
  129. +------+-------+
  130. | id | name |
  131. +------+-------+
  132. | 1 | lilei |
  133. | 2 | rose |
  134. +------+-------+
  135. 2 rows in set (0.00 sec)
  136. mysql> delete from stuinfo where id=1;
  137. Query OK, 1 row affected (0.00 sec)
  138. mysql> select * from stuinfo;
  139. +------+------+
  140. | id | name |
  141. +------+------+
  142. | 2 | rose |
  143. +------+------+
  144. 1 row in set (0.00 sec)
  145. mysql> select version();
  146. +-----------+
  147. | version() |
  148. +-----------+
  149. | 5.5.15 |
  150. +-----------+
  151. 1 row in set (0.00 sec)
  152. mysql> exit
  153. Bye
  154. C:\Windows\system32>mysql --version
  155. mysql Ver 14.14 Distrib 5.5.15, for Win32 (x86)
  156. C:\Windows\system32>mysql -V
  157. mysql Ver 14.14 Distrib 5.5.15, for Win32 (x86)
  158. C:\Windows\system32>mysql -uroot -p
  159. Enter password: ****
  160. Welcome to the MySQL monitor. Commands end with ; or \g.
  161. Your MySQL connection id is 5
  162. Server version: 5.5.15 MySQL Community Server (GPL)
  163. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  164. Oracle is a registered trademark of Oracle Corporation and/or its
  165. affiliates. Other names may be trademarks of their respective
  166. owners.
  167. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  168. mysql> show DATABASES;
  169. +--------------------+
  170. | Database |
  171. +--------------------+
  172. | information_schema |
  173. | mysql |
  174. | performance_schema |
  175. | test |
  176. +--------------------+
  177. 4 rows in set (0.00 sec)
  178. mysql> SHOW DATABASES\g
  179. +--------------------+
  180. | Database |
  181. +--------------------+
  182. | information_schema |
  183. | mysql |
  184. | performance_schema |
  185. | test |
  186. +--------------------+
  187. 4 rows in set (0.00 sec)
  188. mysql> use test;
  189. Database changed
  190. mysql> select * from stuinfo;
  191. +------+------+
  192. | id | name |
  193. +------+------+
  194. | 2 | rose |
  195. +------+------+
  196. 1 row in set (0.00 sec)
  197. mysql> select *
  198. -> from stuinfo;
  199. +------+------+
  200. | id | name |
  201. +------+------+
  202. | 2 | rose |
  203. +------+------+
  204. 1 row in set (0.00 sec)
  205. mysql> SELECT
  206. -> *
  207. -> FROM
  208. -> stuinfo;
  209. +------+------+
  210. | id | name |
  211. +------+------+
  212. | 2 | rose |
  213. +------+------+
  214. 1 row in set (0.00 sec)
  215. mysql> select * from stuinfo;
  216. +------+------+
  217. | id | name |
  218. +------+------+
  219. | 2 | rose |
  220. +------+------+
  221. 1 row in set (0.00 sec)
  222. mysql> #select * from stuinfo;
  223. mysql>