【大数据学习篇14】centos6安装Mysql(下)

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云原生大数据计算服务 MaxCompute,5000CU*H 100GB 3个月
简介: 【大数据学习篇14】centos6安装Mysql

3.4 检查进程,并关闭

[root@localhost 桌面]# ps -aux|grep mysql


Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ


root      2189  0.0  0.1   5124  1396 ?        S    17:24   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid


mysql     2389  0.1  3.1 332068 32420 ?        Sl   17:24   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/lib/mysql/localhost.localdomain.pid --socket=/var/lib/mysql/mysql.sock


root      3066  0.0  0.0   6056   796 pts/0    S+   17:28   0:00 grep mysql


[root@localhost 桌面]# kill -9 2389


[root@localhost 桌面]# service mysql status


SUCCESS! MySQL running (3112)


清理mysql->取消勾选->应用


41679712b6e24533943c7ab26c31db55.png


rm -rf /var/lib/mysql


4. 数据库DML操作

[stu@localhost ~]$ su


密码:


[root@localhost stu]# mysql -u root -p


Enter password: 123456


Welcome to the MySQL monitor.  Commands end with ; or \g.


Your MySQL connection id is 2


Server version: 5.5.48 MySQL Community Server (GPL)


Copyright (c) 2000, 2016, 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.


4.1 查看数据库

mysql> show databases;


+--------------------+


| Database           |


+--------------------+


| information_schema |


| mysql              |


| performance_schema |


| test               |


+--------------------+


4 rows in set (0.02 sec)


4.2 创建数据库

mysql> use mydb1;


Database changed


mysql> show tables;


Empty set (0.00 sec)


create table student (


id int,


name varchar(20),


chinese double,


english double,


math double);


mysql> create table student(


   -> id int,


   -> name varchar(20),


   -> chinese double,


   -> english double,


   -> math double


   -> );


Query OK, 0 rows affected (0.04 sec)


insert into student(id,name,chinese,english,math)


values(1,'张三',78.8,98,66);


insert into student(id,name,chinese,english,math)


values(2,'李四',88.5,68,96);


4.3 添加表列

mysql> alter table student add age varchar(5);


Query OK, 2 rows affected (0.06 sec)


Records: 2  Duplicates: 0  Warnings: 0


mysql> select * from student;


+------+--------+---------+---------+------+------+


| id   | name   | chinese | english | math | age  |


+------+--------+---------+---------+------+------+


|    1 | 张三   |    78.8 |      98 |   66 | NULL |


|    2 | 李四   |    88.5 |      68 |   96 | NULL |


+------+--------+---------+---------+------+------+


2 rows in set (0.00 sec)


4.4 修改列类型

把varhcar(5)改成int类型


mysql> alter table student modify age int;


Query OK, 2 rows affected (0.02 sec)


Records: 2  Duplicates: 0  Warnings: 0


4.5 修改列名

mysql> alter table student change age username varchar(20);


Query OK, 2 rows affected (0.23 sec)


Records: 2  Duplicates: 0  Warnings: 0


mysql> select * from student;


+------+--------+---------+---------+------+----------+


| id   | name   | chinese | english | math | username |


+------+--------+---------+---------+------+----------+


|    1 | 张三   |    78.8 |      98 |   66 | NULL     |


|    2 | 李四   |    88.5 |      68 |   96 | NULL     |


+------+--------+---------+---------+------+----------+


4.6 修改表名

mysql> rename table student to student1;


Query OK, 0 rows affected (0.00 sec)


mysql> select * from student1;


+------+--------+---------+---------+------+----------+


| id   | name   | chinese | english | math | username |


+------+--------+---------+---------+------+----------+


|    1 | 张三   |    78.8 |      98 |   66 | NULL     |


|    2 | 李四   |    88.5 |      68 |   96 | NULL     |


+------+--------+---------+---------+------+----------+


2 rows in set (0.00 sec)


4.7 把student1的表结构和数据保存到新表student

mysql> create table student as select * from student1;


Query OK, 2 rows affected (0.01 sec)


Records: 2  Duplicates: 0  Warnings: 0


mysql> select * from student;


+------+--------+---------+---------+------+----------+


| id   | name   | chinese | english | math | username |


+------+--------+---------+---------+------+----------+


|    1 | 张三   |    78.8 |      98 |   66 | NULL     |


|    2 | 李四   |    88.5 |      68 |   96 | NULL     |


+------+--------+---------+---------+------+----------+


2 rows in set (0.00 sec)


4.8 表结构student添加id主键

mysql> alter table student add constraint primary key(id);


Query OK, 2 rows affected (0.03 sec)


Records: 2  Duplicates: 0  Warnings: 0


4.9 表student1删除id=1的行

mysql> delete from student1 where id=1;


Query OK, 1 row affected (0.00 sec)


mysql> select * from student1;


+------+--------+---------+---------+------+----------+


| id   | name   | chinese | english | math | username |


+------+--------+---------+---------+------+----------+


|    2 | 李四   |    88.5 |      68 |   96 | NULL     |


+------+--------+---------+---------+------+----------+


1 row in set (0.00 sec)


4.10 表student1删除全部数据

mysql> truncate table student1;


Query OK, 0 rows affected (0.01 sec)


mysql> select * from student1;


Empty set (0.00 sec)


4.11 表student1删除

mysql> drop table student1;


5.  数据库用户操作

[stu@localhost ~]$ su


密码:


[root@localhost stu]# mysql -u root -p


Enter password: 123456


Welcome to the MySQL monitor.  Commands end with ; or \g.


Your MySQL connection id is 2


Server version: 5.5.48 MySQL Community Server (GPL)


Copyright (c) 2000, 2016, 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.


5.1 创建用户(@本机用户,%网络用户)

mysql> create user mysql@localhost identified by '123456';


Query OK, 0 rows affected (0.00 sec)


mysql> grant select on *.* to mysql@localhost;


Query OK, 0 rows affected (0.00 sec)


5.2 查看用户权限

mysql> show grants for mysql@localhost;


+---------------------------------------------------------------------------------------------------------------+


| Grants for mysql@localhost                                                                                    |


+---------------------------------------------------------------------------------------------------------------+


| GRANT SELECT ON *.* TO 'mysql'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |


+---------------------------------------------------------------------------------------------------------------+


1 row in set (0.00 sec)


5.3 撤消用户权限

mysql> revoke select on *.* from mysql@localhost;


Query OK, 0 rows affected (0.02 sec)


5.4 修改密码

mysql> update mysql.user set password=password('234567') where user='mysql';


Query OK, 1 row affected (0.00 sec)


Rows matched: 1  Changed: 1  Warnings: 0


mysql> flush privileges;


Query OK, 0 rows affected (0.00 sec)


5.5 打开新终端

[root@localhost mysql]# mysql -u mysql -p


Enter password: 123456


ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: YES)


[root@localhost mysql]# mysql -u mysql -p


Enter password: 234567


Welcome to the MySQL monitor.  Commands end with ; or \g.


Your MySQL connection id is 5


Server version: 5.5.48 MySQL Community Server (GPL)


Copyright (c) 2000, 2016, 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>


5.6 要回去用root账户删除mysql账户

mysql> drop user mysql;


6. 数据库查询操作

6.1 进入数据库

[root@localhost mysql]# mysql -u root -p


mysql> user mydb1;


mysql> select * from student where chinese<80;


+----+--------+---------+---------+------+----------+


| id | name   | chinese | english | math | username |


+----+--------+---------+---------+------+----------+


|  1 | 张三   |    78.8 |      98 |   66 | NULL     |


+----+--------+---------+---------+------+----------+


mysql> select * from student where chinese>80 and chinese<90;


+----+--------+---------+---------+------+----------+


| id | name   | chinese | english | math | username |


+----+--------+---------+---------+------+----------+


|  2 | 李四   |    88.5 |      68 |   96 | NULL     |


+----+--------+---------+---------+------+----------+


1 row in set (0.00 sec)


mysql> select * from student where chinese between 80 and 90;


+----+--------+---------+---------+------+----------+


| id | name   | chinese | english | math | username |


+----+--------+---------+---------+------+----------+


|  2 | 李四   |    88.5 |      68 |   96 | NULL     |


|  3 | Li     |      90 |      90 |   47 | NULL     |


+----+--------+---------+---------+------+----------+


2 rows in set (0.00 sec)


mysql> select * from student order by chinese desc;


+----+--------+---------+---------+------+----------+


| id | name   | chinese | english | math | username |


+----+--------+---------+---------+------+----------+


|  3 | Li     |      90 |      90 |   47 | NULL     |


|  2 | 李四   |    88.5 |      68 |   96 | NULL     |


|  1 | 张三   |    78.8 |      98 |   66 | NULL     |


+----+--------+---------+---------+------+----------+


3 rows in set (0.00 sec)


mysql> select id,name,(chinese+english+math) score from student;


+----+--------+-------+


| id | name   | score |


+----+--------+-------+


|  1 | 张三   | 242.8 |


|  2 | 李四   | 252.5 |


|  3 | Li     |   227 |


+----+--------+-------+


3 rows in set (0.00 sec)


mysql> select * from (select id,name,(chinese+english+math) score from student) vw order by vw.score;


+----+--------+-------+


| id | name   | score |


+----+--------+-------+


|  3 | Li     |   227 |


|  1 | 张三   | 242.8 |


|  2 | 李四   | 252.5 |


+----+--------+-------+


3 rows in set (0.00 sec)


一键三连!


一键三连!


相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
4天前
|
监控 Linux PHP
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
51 20
|
1月前
|
存储 分布式计算 Hadoop
Centos7.9安装kerberos
Centos7.9安装kerberos
82 25
|
27天前
|
存储 Shell 网络安全
Centos7.9安装openldap
Centos7.9安装openldap
52 16
|
28天前
|
数据可视化 Linux 应用服务中间件
Centos7.9安装phpldapadmin
Centos7.9安装phpldapadmin
56 15
|
1月前
|
安全 关系型数据库 MySQL
CentOS7仅安装部署MySQL80客户端
通过上述步骤,你可以在CentOS 7上成功安装并配置MySQL 8.0客户端。这个过程确保你能够使用MySQL客户端工具连接和管理远程的MySQL数据库,而不需要在本地安装MySQL服务器。定期更新MySQL客户端可以确保你使用的是最新的功能和安全修复。
155 16
|
1月前
|
网络协议 Java 应用服务中间件
centos7环境下tomcat8的安装与配置
本文介绍了在Linux环境下安装和配置Tomcat 8的详细步骤。首先,通过无网络条件下的文件交互软件(如Xftp 6或MobaXterm)下载并解压Tomcat安装包至指定路径,启动Tomcat服务并测试访问。接着,修改Tomcat端口号以避免冲突,并部署Java Web应用项目至Tomcat服务器。最后,调整Linux防火墙规则,确保外部可以正常访问部署的应用。关键步骤包括关闭或配置防火墙、添加必要的端口规则,确保Tomcat服务稳定运行。
|
3月前
|
SQL 存储 Linux
从配置源到数据库初始化一步步教你在CentOS 7.9上安装SQL Server 2019
【11月更文挑战第16天】本文介绍了在 CentOS 7.9 上安装 SQL Server 2019 的详细步骤,包括配置系统源、安装 SQL Server 2019 软件包以及数据库初始化,确保 SQL Server 正常运行。
151 4
|
3月前
|
SQL 存储 Linux
从配置源到数据库初始化一步步教你在CentOS 7.9上安装SQL Server 2019
【11月更文挑战第8天】本文介绍了在 CentOS 7.9 上安装 SQL Server 2019 的详细步骤,包括系统准备、配置安装源、安装 SQL Server 软件包、运行安装程序、初始化数据库以及配置远程连接。通过这些步骤,您可以顺利地在 CentOS 系统上部署和使用 SQL Server 2019。
167 1
|
3月前
|
SQL 存储 Linux
从配置源到数据库初始化一步步教你在CentOS 7.9上安装SQL Server 2019
【11月更文挑战第7天】本文介绍了在 CentOS 7.9 上安装 SQL Server 2019 的详细步骤,包括系统要求检查与准备、配置安装源、安装 SQL Server 2019、配置 SQL Server 以及数据库初始化(可选)。通过这些步骤,你可以成功安装并初步配置 SQL Server 2019,进行简单的数据库操作。
|
3月前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。通过具体案例,读者可以了解如何准备环境、下载源码、编译安装、配置服务及登录 MySQL。编译源码安装虽然复杂,但提供了更高的定制性和灵活性,适用于需要高度定制的场景。
202 3