mysql的安装和使用

mysql的安装

 我使用的mysql的版本是mysql5.7的。曾经出现过“Can't connect to MySQL server on localhost (10061)解决方法”的问题。

  • 首先,在官网上下载mysql-community-server的软件安装包(暂且理解为mysql服务端)。解压直接使用。
  • 其次,配置path,并以管理员身份打开cmd。执行命令mysqld --install 。(暂且理解为console版本的客户端)(删除的命令是sc delete mysql)
  • 接着,执行命令net start mysql .用于开启mysql服务。(关闭命令是net stop mysql ).
  • 最后,mysql -u root -p.进去即可(退出是exit)。

我出现问题的原因在于第三步失败,原因未知。处理方法:

在执行“mysql --install”之后,执行命令,“mysqld --initialize --user=root --console”,结果如图:

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysqld --initialize --user=root --console
2016-10-29T01:35:44.309833Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see doc
umentation for more details).
2016-10-29T01:35:46.659968Z 0 [Warning] InnoDB: New log files created, LSN=45790

2016-10-29T01:35:47.154996Z 0 [Warning] InnoDB: Creating foreign key constraintsystem tables.
2016-10-29T01:35:47.362008Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating
a new UUID: 043563f4-9d78-11e6-a8c8-606dc79c383c.
2016-10-29T01:35:47.388009Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-10-29T01:35:47.401010Z 1 [Note] A temporary password is generated for root@localhost: u).ig.Gd.7hW

翻译最后一行可知,临时密码就知道了。开启服务且进入即可(原来的步骤)。

修改密码:set password=password('123456') 。安装结束!!!

对数据库的命令操作

数据库的操作主要是增,删,查,和使用。对应的动作是create,drop,show,use.

另外,当设计到对某个具体的数据库d操作时,数据库要用单数即database,当涉及到多个数据库的时候,就要使用复数

databases。

例如:

create database  stu;
drop database stu;
show databases ;
use database stu;//或者直接是use stu;

对数据结构(即数据表)的操作

数据表的操作和数据库的很像。分别是,增,删,修改(最麻烦),查。分别对应的是,create,drop,alter,show(desc).

当涉及单个表的时候用table,当涉及多个表的时候就是tables。

create table stu(id int,sex char);
drop table stu;
show tables;
desc stu;
//改。
//增加一列
alter table stu add age int;
//删除一列
alter table stu drop column age;
//修改列名
alter table stu exec sp_rename('stu.age','three')
//修改列类型
alter table stu alter column age varchar(40);

修改列名和修改列类型操作失败。原因未知。

对数据的操作

对数据的操作,主要有增,删,查,改四类操作。然而,在对数据进行操作之前首先要对数据建模,建立数据结构,就是

创建一个数据表。

create  table stu
(
id int primary key,
sex char  not null
);

增,删,改,查。分别对应的操作是,insert ,delete ,update,select

增:

//增加一条记录
insert into stu
value(1,12,'nan');

//增加多条记录
insert into stu
select * from stu;

删:

删除数据
delete from stu
where id=1;
删除表格
drop table stu;

改:

update stu
set age=100
where id=2;

查(查找):

1.条件查询

select id from stu
where id >=2;

2.模糊查询

模糊查询,like
select * from stu
where sex like 'b%';
数字的集合,between and
select * from stu
where sex between 18 and 20;
字符串的集合 in
select * from stu
where sex in ('boy','girl');

3.分组查询(得到的是统计表)

sql函数:分组时才使用到。

min(),max(),sum(),avg(),count().括号里面是列名字。

select id,count(ageg) from stu
group by  id;

4.连接查询

select * from stu,two
where stu.id=stu.id;

排序:

默认是1,2,3升序。
select * from stu
order by id;

注意;只要是涉及到分组得到的一定是统计表,使用了某个函数。其他的查询都是在原始表上进行的。至于排序,按需要,可加

可不加。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值