栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux mysql学习笔记

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux mysql学习笔记

此文是我从网上学习MySQL做的亲手笔记,希望能给大家提供帮助,仅供参考!

一、安装MySQL

1、源代码安装

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update yum install mysql-server

2、权限设置:

chown mysql:mysql -R /var/lib/mysql

3、初始化 MySQL:

mysqld ----user=mysql --initialize

4、启动 MySQL:

systemctl start mysqld

二、修改mysql密码

1、yum install mysql mysql-admin

2、创建mysql密码

mysqladmin -uroot password cityhosue

3、修改mysql密码

mysqladmin -uroot -pcityhouse password cityhouse1

4、进入命令行修改

SET PASSWORD FOR '用户名'@'主机' = PASSWORd(‘密码');

set password for root@localhost = password('cityre');

三、数据库操作学习

1、创建数据库

create database cityhouse;

drop database cityhouse;

2、导出数据库

mysqldump -uroot -pcityre --events mysql > 2.sql

3、导入数据库

mysql -uroot -pcityre mysql < 2.sql

4、进入数据库

use mysql;

5、查看数据表

show tables;

6、创建数据表

create table (表名)(列名 列数据类型,列名 列数据类型,····················);

create table city(xin int,qing date,dao text);

7、查看建表数据

show create table city;

8、插入数据

insert into city (xin,qing,dao) values (2018,'2018-04-21',"xinkaishi");

注意:如果数据是字符型,必须使用单引号或者双引号,如:"value"。

9、插入某一列一个数据

insert into city (qing) values ('2021-09-30');

10、插入表列

alter table (表名) add (列名) (数据类型);

alter table city add xi text;

11、更改第4列第1行的数据

update city set xi="cityhouse" where xin=2018;

12、删除表数据

delete from student where name=1;

13、利用order进行排序

select * from city order by xin;

14、统计排序的个数

select *, count(*) from city order by xin;

15、使用 GROUP BY 语句 将数据表按名字进行分组,

select * from city group by qing;

16、并统计每个人有多少条记录:

select *, count(*) from city group by qing;

17、查看表help_category的表数据

select * from help_category;

18、查看表help_category表help_category_id和表name两列数据

select help_category_id,name from help_category;

19、查看表parent_category_id数据是4的数据信息,大于0小于8

select parent_category_id from help_category where parent_category_id > 0 and

parent_category_id < 8;

select * from help_category where parent_category_id < 8 and parent_category_id > 0;

20、查看表parent_category数据不为4和21的数据信息 

select * from help_category where parent_category_id != 4 and parent_category_id != 21;

21、查看表parent_category数据不为4和21,name为MBR的数据信息,字符串需要加引号

select * from help_category where parent_category_id != 4 and parent_category_id != 21 and name = “MBR”;

22、筛选表partent_category表中带Data的字符串

select * from help_catagory where name like '%Data%';

23、筛选表partent_category表中 不带 Data的字符串

select * from help_catagory where name like not '%Data%';

24、查看不在一个连续范围内的数据信息

select * from help_category where parent_category_id in (8,21);

25、查看在一个连续范围内的数据信息

select * from help_category where parent_category_id between 8 and 21;

26、查看表数值最大值和最小值

select max(parent_category_id) from help_category;

select min(parent_category_id) from help_category;

27、计算表的数值总和

select sum(parent_category_id) from help_category;

28、计算表的数值平均值

select avg(parent_category_id) from help_category;

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/458129.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号