Java Web基础入门( 四 )


复制我们的临时密码/r..
命令行启动MySQL:

Java Web基础入门

文章插图
mysqld --console
新开一个cmd,命令行输入账号密码mysql -u root -p
C:\Users\Ryanλ mysql -u root -pEnter password: ************Welcome to the MySQL monitor.Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.7.20Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
然后就连接到MySQL了 。第一个命令行就是启动mysql,第二个命令行就是,连接MySQL 。现在修改我们的root密码
mysql> set password=password('123456');Query OK, 0 rows affected, 1 warning (0.00 sec)
然后,关闭,输入exit退出 。重新以新密码登陆(不要自己难为自己,设置密码为是最佳选择).
确认成功就安装完毕 。账号为root, 密码为 。
基本操作
关于MySQL的基本语法,学习 即可 。
这里简单记录几个简单的概念 。
MySQL以不同的为单位存储数据 。所以,开发数据库的时候,先要创建一个 。
查看已有的
mysql> show databases;+--------------------+| Database|+--------------------+| information_schema || mysql|| performance_schema || sys|+--------------------+4 rows in set (0.00 sec)
创建我们的
mysql> create database if not exists springboot_demo charset utf8 collate utf8_general_ci;Query OK, 1 row affected (0.01 sec)
进入:
mysql> use springboot_demoDatabase changed
创建表
查看当前的所有表
mysql> use springboot_demoDatabase changedmysql> show tables;Empty set (0.00 sec)
创建一个表room
mysql> create table if not exists room (->id INT(11) NOT NULL AUTO_INCREMENT,->`name` VARCHAR(80) NOT NULL,->`comment` VARCHAR(200),->create_date DATE,->update_date DATE,->PRIMARY KEY(id)-> )ENGINE=InnoDB DEFAULT CHARSET=utf8;Query OK, 0 rows affected (0.08 sec)
插入一条记录
mysql> insert into room(`name`, `comment`, `create_date`, `update_date`) values ("大床房", "", "2017-11-26","2017-11-2611:00:00");Query OK, 1 row affected, 1 warning (0.01 sec)mysql>insert into room(`name`, `comment`, `create_date`, `update_date`) values ("双人床房", "有窗户", "2017-11-26","2017-11-26 11:00:00");Query OK, 1 row affected, 1 warning (0.01 sec)
查看所有记录
mysql> select * from room;+----+----------+---------+-------------+-------------+| id | name| comment | create_date | update_date |+----+----------+---------+-------------+-------------+|1 | 大床房|| 2017-11-26| 2017-11-26||2 | 双人床房 | 有窗户| 2017-11-26| 2017-11-26|+----+----------+---------+-------------+-------------+2 rows in set (0.00 sec)
更新一条记录
mysql> update room set comment="无窗" where id=1;Query OK, 1 row affected (0.01 sec)Rows matched: 1Changed: 1Warnings: 0mysql> select * from room;+----+----------+---------+-------------+-------------+| id | name| comment | create_date | update_date |+----+----------+---------+-------------+-------------+|1 | 大床房| 无窗| 2017-11-26| 2017-11-26||2 | 双人床房 | 有窗户| 2017-11-26| 2017-11-26|+----+----------+---------+-------------+-------------+2 rows in set (0.00 sec)
删除一条记录