MySQL的启动与简单命令_002
三、启动MySQL
文章目录
- 三、启动MySQL
- 3.1.MySQL启动和停止
- 3.1.1.方式一:服务配置
- 3.1.1.方式二:以管理员运行DOS命令
- 3.2.MySQL服务登录与退出
- 3.2.1.方式一:MySQL服务端
- 3.2.2.方式二:以管理员DOS命令
- 3.2.3.登录失败
- 3.3.MySQL常见3命令
- 3.3.1.命令
- 3.3.2.实例与命令详解
3.1.MySQL启动和停止
3.1.1.方式一:服务配置
- 此电脑-右击-管理-服务和应用程序-服务-MySQLyanyu安装配置时设置的服务名字,默认就是MySQL,此处我的服务名字是MySQLyanyu-双击-进行相应的配置
- 设置
- 经常使用,设置为自动
- 不经常使用,建议设置为手动
3.1.1.方式二:以管理员运行DOS命令
点击O搜索,输入cmd-命令提示符-右击-以管理员运行-输入:
- net stop mysqlyanyu服务名字+enter关闭MySQL服务
- net start mysqlyanyu+enter开启MySQL服务
Microsoft Windows [版本 10.0.17763.1577] (c) 2018 Microsoft Corporation。保留所有权利。C:\Users\Administrator>net stop mysqlyanyu MySQLyanyu 服务正在停止. MySQLyanyu 服务已成功停止。C:\Users\Administrator>net start mysqlyanyu MySQLyanyu 服务正在启动 ... MySQLyanyu 服务已经启动成功。C:\Users\Administrator>
3.2.MySQL服务登录与退出
背景:MySQL相当于是一个仓库,MySQL服务的启动大门可用与停止大门不可用就是相当于仓库的大门,开启MySQL服务后,仓库大门便是可用,便可以进行刷卡进行身份验证MySQL的登录与退出
使用配置MySQL使设置的root密码,进行登录,我的MySQL目前是只有root一个用户,也是最高权限的用户
3.2.1.方式一:MySQL服务端
点击win键--MySQL-直接输入root密码
不建议使用,因 为该方式只能用于root用户,对于普通用户无法使用,目前我们只设置了root用户,但是以后在工作那样的实际操作环境中,肯定不会只有一个root用户
Enter password: **** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.15 MySQL Community Server (GPL)Copyright (c) 2000, 2010, 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>
3.2.2.方式二:以管理员DOS命令
- 以管理员身份进入DOS命令界面
- 输入以下MySQL命令:
- mysql -h localhost -P 3306 -u root -p
- 输入root密码
- 解释:
- -h 登录那台机器的MySQL服务端本次登录的是“本地主机”
- -P大写,代表的是端口号,未更改的话,默认端口号3306
- -u 用户名
- -p小写,也就是用户名的登录密码
- 可以在-p后面只接输入密码p与密码之间不可以有空格,但是不建议这样操作,存在暴露密码风险
- enter
- 输入用户密码(即我们这里的root密码)
- 退出;
- exti
ctrl
+c
Microsoft Windows [版本 10.0.17763.1577]
(c) 2018 Microsoft Corporation。保留所有权利。C:\Users\Administrator>mysql -h localhost -P 3306 -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.15 MySQL Community Server (GPL)Copyright (c) 2000, 2010, 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>
若是登录本地主机而且端口号是3306,命令可以简写:
mysql -u root -p
C:\Users\Administrator>mysql -u root -p Enter password: **** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.5.15 MySQL Community Server (GPL)Copyright (c) 2000, 2010, 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>
3.2.3.登录失败
操作性失误
- 用户名和密码不匹配
- 登录命令写错
- 非管理员模式
- MySQL服务为开启
环境变量错误
- 环境变量未配置
- 找到MySQL的bin目录-点击
- 将该路径复制
- 此电脑-右击-属性-高级系统设置-环境变量-系统变量-双机path–新建-粘贴MySQL的bin路径-确定
- 环境变量紊乱
- 原因:path环境变量时从前往后查询,若是在MySQL的bin路径不是在最前面,就可能出现紊乱问题
- 此电脑-右击-属性-高级系统设置-环境变量-系统变量-双机path-编辑文本-全部复制-新建一个TXT文本-粘贴-将“C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin;”剪切到最前面-
ctrl+a
+ctrl+c
(也就将MySQL路径剪切到了最前的,修改后的整个文档进行复制) - 此电脑-右击-属性-高级系统设置-环境变量-系统变量-双机path-编辑文本-删除-粘贴也就将MySQL路径剪切到了最前的,修改后的整个文档
- 环境变量未配置
3.3.MySQL常见3命令
登录MySQL
3.3.1.命令
命令 | 含义 |
---|---|
; or 0\g
|
分割两个不同的命令 |
show databases;
|
查看仓库里有哪些小仓库 |
use 库名;
|
进入某个库 |
show tables;
|
查看库里有什么表 |
select database()
|
查看处于哪个库 |
create table 表名(指定id和name列以及类型);
|
创建表 |
desc 表名;
|
查看表的结构 |
select * from 表名;
|
查看表的数据 |
insert into 表名 (id,name) values(列号,'内容');
|
向表插入数据,电脑重启后,再次连接到数据库,数据依然存在 |
update 表名 set name='jessi' where id=1;
|
将表中id=3那列的数据更新为jessi |
delete from yanyu666 where id=3;
|
删除“烟雨666”这个表id=3的数据 |
3.3.2.实例与命令详解
Microsoft Windows [版本 10.0.17763.1577]
(c) 2018 Microsoft Corporation。保留所有权利。C:\Users\Administrator>mysql -h localhost -P3306 -u root -p
//登录MySQL服务端
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.15 MySQL Community Server (GPL)Copyright (c) 2000, 2010, 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> show databases
//缺少英文分号-> show databases;
//未在mysql>输入
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'show databases' at line 2
mysql> show databases;
//查看有哪些库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
/*
1.有四个自带的默认数据库
2.mysql用于保存用户信息
3.information_schema保存一些源数据
4.performance_schema收集性能参数
5.test一种测试数据库,里面没有表,是空的数据库,
可以在里面建表,也可以删除库、修改库,前面三个库不可以动
*/mysql> use test;
//进入某个库
Database changed
mysql> show table;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mysql> show tables;
//查看库里有什么表
Empty set (0.00 sec)
//空表,说明test库确实是空库
/*处于test库如何查看mysql库里有什么表?
1.重复上面的,进入到MySQL库进行查看
2.以下命令
*/
mysql> show tables from mysql;
//就在test得库中,不出去,显示来自于
mysql的表
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.03 sec)mysql> select database();
//查看当前处于那个库?
+------------+
| database() |
+------------+
| test |
+------------+
1 row in set (0.00 sec)
//在test库中创建一个名字为yanyu666的表
mysql> create table yanyu666(-> id int,//设置id列类型为int-> name varchar(20));//设置name列为字符串类型//注意在MySQL中,字符串用varchar//不是java种的String
Query OK, 0 rows affected (0.02 sec)mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| yanyu666 |
+----------------+
1 row in set (0.00 sec)
/*证明yanyu666的表创建成功*/
mysql>
mysql> desc yanyu666;
/*查看表的结构*/
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)
/*
1.field 字段(列)有两个,id、name
2、type 列对应的类型,一个int varchar(字符串)
3、以及其它约束
*/
mysql> select * from yanyu666;
/*查看表里有什么数据,结果显然是没有数据,
yanyu666是我们新建的表*/
Empty set (0.00 sec)
mysql> insert into yanyu666 (id,name) values(1,'yanyu');
Query OK, 1 row affected (0.01 sec)
/*在yanyu666表中插入数据
insert into 表名 (id,name)
values(id号,‘内容’);
*/
mysql> insert into yanyu666 (id,name) values(3,'yanyu666');
Query OK, 1 row affected (0.01 sec)mysql> select * from yanyu666;
+------+----------+
| id | name |
+------+----------+
| 1 | yanyu |
| 3 | yanyu666 |
+------+----------+
2 rows in set (0.00 sec)
mysql> update yanyu666 set name='jessi' where id=1;
/*
将表中id=3那列的数据更新为jessi
*/
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from yanyu666;
+------+----------+
| id | name |
+------+----------+
| 1 | jessi |
| 3 | yanyu666 |
+------+----------+
2 rows in set (0.00 sec)mysql> delete from yanyu666 where id=3;
Query OK, 1 row affected (0.01 sec)
/*
删除“烟雨666”这个表id=3的数据
*/
mysql> select * from yanyu666;
+------+-------+
| id | name |
+------+-------+
| 1 | jessi |
+------+-------+
1 row in set (0.00 sec)
-+
| 1 | jessi |
| 3 | yanyu666 |
+------+----------+
2 rows in set (0.00 sec)mysql> delete from yanyu666 where id=3;
Query OK, 1 row affected (0.01 sec)
/*
删除“烟雨666”这个表id=3的数据
*/
mysql> select * from yanyu666;
+------+-------+
| id | name |
+------+-------+
| 1 | jessi |
+------+-------+
1 row in set (0.00 sec)
MySQL的启动与简单命令_002相关推荐
- MySQL 查看表结构简单命令。
MySQL 查看表结构简单命令. 一.简单描述表结构,字段类型desc tabl_name;显示表结构,字段类型,主键,是否为空等属性,但不显示外键. 二.查询表中列的注释信息select * fro ...
- mysql 中启动服务的命令 、登录命令、退出命令 mysql 的常用命令
1.cmd 以管理员执行 下面命令 启动服务 :net start mysql57 关闭 服务:net stop mysql57 查看mysql 的版本信息 : mysql -V 指定主机地址登录: ...
- 用于退出mysql的命令有,mysql 中启动服务的命令 、登录命令、退出命令 mysql 的常用命令...
1.cmd 以管理员执行 下面命令 启动服务 :net start mysql57 关闭 服务:net stop mysql57 查看mysql 的版本信息 : mysql -V 指定主机地址登录: ...
- php查看表创建结构,MySQL 查看表结构简单命令
一.简单描述表结构,字段类型 desc tabl_name; 显示表结构,字段类型,主键,是否为空等属性,但不显示外键. 例如:desc table_name 二.查询表中列的注释信息 select ...
- mysql execute指令_MYSQL简单命令
常用 mysql 操作指令: 连接:mysql -u用户名 -p密码 退出:mysql>exit; 建数据库:mysql>create database ???; 显示数据库:mysql& ...
- mac nginx安装、启动、简单命令
一. brew 安装 打开mac终端,输入以下命令: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/ins ...
- MySQL启动和关闭命令
文章目录 一.Windws系统 二.Linux系统 1.service命令 2. /etc/init.d/mysql 3.mysqld命令 4.mysqld_safe命令 5.mysqld_multi ...
- mysql数据库没启动命令_mysql数据库服务启动和停止命令介绍(转载)
mysql数据库启动与停止我这里给大家介绍在windows系统与linux内核的各种系统中的操作命令,希望对大家会有所帮助哦. MySQL在windows.Linux的启动.停止的方法 一.windo ...
- fedora mysql 开机启动服务_linux -- 启动时启动服务或者执行命令
运行等级 首先,我们需要知道Linux系统关于运行等级的知识.在不同的linux系统上(例如ubuntu和Fedora)这些数字与和所代表的意义可能不同,但主要的有以下几个: 单用户模式. 多用户模式 ...
最新文章
- NVIDIA Turing Architecture架构设计(上)
- python代码需要背吗-Python 的库、方法这么多,写程序的时候能记住吗?
- Android运行时识别API版本
- word操作快捷键记录
- Vscode html代码快速填写
- 向量召回 MIND多兴趣双塔模型
- 常用数据类型(C#)
- centos7.4安装mysql5.7_centos7.4三种方式安装mysql5.7
- python selenium爬虫需要账号和密码登陆的网页_如何使用selenium和requests组合实现登录页面...
- Matlab45度边缘连接,为什么Matlab的delaunayn()的delaunay边缘与非相邻的Voronoi区域连接点?...
- Xshell利用密钥远程登录Linux
- Windows说明Linux分区和挂载点
- python分类识别_Python构建图像分类识别器的方法
- duilib中各控件响应的消息类型
- 服务器2003系统序列号,Windows Server 2003 R2 With Sp2 序列号
- JSP毕业设计源码带论文和答辩、大作业、实例程序源码下载合集【10套】
- 星星之火-49:5G 移动边缘计算MEC快览
- 使用DCMTK实现DICOM文件的读写
- “振心计划”受益房东超20万,爱彼迎中国活跃房源同比增长超两成
- 哈尔滨工业大学邮件系统客户端设置
热门文章
- js实现: while实现1-100相加求和, while do...while验证用户名和密码, 打印菱形、三角形,大小和尚分馒头。
- 幼儿使用计算机需要注意事项,儿童玩电脑的优缺点及注意事项
- cnn是深度神经网络吗,cnn神经网络算法
- 2015华为校园招聘机试题一
- 无人机寻迹要两个单片机吗_单片机寻迹小车程序
- 23种设计模式:(二)结构型模式
- 电子元器件贸易企业如何借助ERP系统,解决仓库管理难题?
- Motorola和TI的SPI的区别
- LS-WXL/E改机应用流程全攻略(改机+下载工具安装)
- 天枰座定时任务处理框架