[MySQL / Mariadb] 数据库学习-Linux中安装MySQL,YUM方式

news2024/9/21 12:31:29

[Mariadb] 数据库学习笔记

  • 在Linux中安装MySQL,YUM方式
  • mariadb 介绍
  • 安装启服务
  • 初始配置
    • 修改密码
  • 密码策略,默认策略是1
      • show variables; 查所有变量
      • show variables like "%变量%"; 查特定的变量参数
      • 临时:
      • 永久:
  • MySQL基本操作
    • 连接SQL服务
    • SQL命令使用规则
    • SQL命令分类
    • 库管理命令:库类似于文件夹,用来存储表
      • 综合练习

在Linux中安装MySQL,YUM方式

新安装的MySQL,是没有密码的
进入方法:

[root@control ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.17 Source distribution

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

配置密码:

mysql> alter user root@"localhost" identified by "111";
Query OK, 0 rows affected (0.00 sec)

[root@control ~]# mysql -uroot -p111

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.17 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

mariadb 介绍

1)常见软件
主流操作系统:Unix、Linux、Windows

			软件名		开源	跨平台	厂商
	Oracle		否	是	甲骨文
	MySQL		是	是	甲骨文
	SQL Server	否	否	微软
	DB2		否	是	IBM
	Redis		是	是	开源软件
	Memcached	是	是	开源软件
	MongoDB	是	是	开源软件

2)专业术语
	DB(DataBase)
		数据库
		依照某种数据模型进行组织并存放到存储器的数据集合
	DBMS(DataBase Management System)
		数据库管理系统
		用来操纵和管理数据库的服务软件
	DBS(DataBase System)
		数据库系统:即DB+DBMS
		指带有数据库并整合了数据库管理软件的计算机系统

3)MySQL介绍
	起源与发展:
		应用最广泛的开源数据库软件
			最早属于瑞典的MySQL AB公司
			2008年1月,MySQL AB被Sun收购
			2009年4月,SUN被Oracle收购
		崭新的开源分支MariaDB
			为应付 MySQL可能会闭源的风险而诞生
			由MySQL原作者 Widenius主导开发
			与MySQL保持最大程度兼容

4)特点与应用
	主要特点:
		适用于中小规模,关系型数据库系统
		支持Linux、Unix、Windows等多种操作系统
		支持Python、Java、Perl、PHP等编程语言
	典型应用环境:
		LAMP平台,与Apache HTTP Server组合
		LNMP平台,与Nginx组合

安装启服务

环境前提:关闭防火墙、selinux、YUM源

[root@myserver ~]# yum -y install mariadb-server
Last metadata expiration check: 1:24:11 ago on Thu 04 May 2023 09:23:23 AM UTC.
Package mariadb-server-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@myserver ~]# systemctl start mariadb
[root@myserver ~]# systemctl enable mariadb
[root@myserver ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2023-05-04 06:21:27 UTC; 4h 26min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 20175 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 31 (limit: 23978)
   Memory: 85.6M
   CGroup: /system.slice/mariadb.service
           └─20175 /usr/libexec/mysqld --basedir=/usr

相关参数:
			/etc/my.cnf	主配置文件
			/var/lib/mysql	数据库目录
			默认端口号	3306
			进程名		mysqld
			传输协议		TCP
			进程所有者	mysql
			进程所属组	mysql
			错误日志文件	/var/log/mariadb/mariadb.log

初始配置

数据库管理员名为root

默认仅允许root本机连接

首次登陆密码在安装软件时随机生成
		
随机密码存储在日志文件/var/log/mysqld.log里
		
连接命令:mysql  -h数据库地址  -u用户  -p密码

grep  password  /var/log/mariadb/mariadb.log			##查看初始化密码

mysql  -hlocalhost  -uroot  -p'密码'			##使用初始化密码登陆数据库

例:

[root@myserver ~]# mysql -uroot -p222
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| aab                |
| aac                |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
5 rows in set (0.003 sec)

MariaDB [(none)]>

修改密码

MariaDB [(none)]> alter user root@"localhost" identified by "111qwe..A";
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> exit
Bye
[root@myserver ~]# mysql -uroot -p111qwe..A
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 22
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit
Bye
[root@myserver ~]#

密码策略,默认策略是1

修改密码策略
LOW(0) 长度
MEDIUM(1) 长度、数字、小写/大写、和特殊字符
STRONG(2) 长度、数字、小写/大写、和特殊字符、字典文件

show variables; 查所有变量

show variables like “%变量%”; 查特定的变量参数

临时:

	mysql  -uroot  -p密码				
	##临时修改密码策略,重启服务后会失效
	show  variables  like  "%password%";			
	##查看系统中和密码相关的变量
	set  global  validate_password_policy=0;			
	##设置密码策略为LOW,只检验长度
	set  global  validate_password_length=6;			
	##设置密码的长度最短为6位
	show  variables  like  "%password%";

永久:

	vim  /etc/my.cnf					##永久修改密码策略
	[mysqld]				
	validate_password_policy=0				
	##设置密码策略为LOW,只检验长度
	validate_password_length=6				
	##设置密码的长度最短为6位
	:wq
	
	systemctl  restart  mysqld
	mysql  -uroot  -p密码
	show  variables  like  "%password%";

例:
我这里找到的密码策略和变量没有练习中的那些

MariaDB [(none)]> show variables like "%password%";
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| old_passwords              | OFF   |
| report_password            |       |
| strict_password_validation | ON    |
+----------------------------+-------+
3 rows in set (0.004 sec)

MySQL基本操作

连接SQL服务

连接方式:客户端连接MySQL服务的方法
命令行
web页面
安装图形软件
编写脚本(PHP、Java、Python…)
使用mysql 命令:
mysql -h服务器IP -u用户名 -p密码 [数据库名]
quit 或 exit 退出

2)数据存储流程
	客户端把数据存储到数据库服务器上的步骤
		连接数据库服务器
		建库			##相当于创建文件夹
		建表			##相当于创建文本文件
		插入记录			##相当于在文件文件中写入内容
		断开连接			

SQL命令使用规则

SQL命令不区分字母大小写(密码,变量值除外)
每条SQL命令以**;**结束
默认命令不支持Tab键自动补齐
\c 终止sql命令

SQL命令分类

	管理数据库使用SQL(结构化查询语言)
	DDL	数据定义语言:如 create、alter、drop
	DML	数据操作语言:如 insert、update、delete
	DCL	数据控制语言:如 grant、revoke
	DTL	数据事务语言:如 commit、rollback、savepoint

库管理命令:库类似于文件夹,用来存储表

	show  databases;		##显示已有的库
	select  user();		##显示连接用户
	use  库名;		##切换库
	select  database();		##显示当前所在的库
	create  database  库名;	##创建新库
	show  tables;		##显示已有的表
	drop  database  库名;	##删除库
例:
MariaDB [(none)]> show databases;     #显示已有的库
+--------------------+
| Database           |
+--------------------+
| aab                |
| aac                |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
5 rows in set (0.003 sec)

MariaDB [(none)]> select user();    #显示连接用户
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.002 sec)

MariaDB [(none)]> use mysql;     #切换库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

MariaDB [mysql]> select database();     #显示当前所在的库
+------------+
| database() |
+------------+
| mysql      |
+------------+
1 row in set (0.003 sec)


MariaDB [mysql]> create database aaa;   #创建库
Query OK, 1 row affected (0.003 sec)

MariaDB [mysql]> show tables;    #显示当前库已有的表
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| column_stats              |
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| gtid_slave_pos            |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| index_stats               |
| innodb_index_stats        |
| innodb_table_stats        |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| roles_mapping             |
| servers                   |
| slow_log                  |
| table_stats               |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| transaction_registry      |
| user                      |
+---------------------------+
31 rows in set (0.002 sec)

MariaDB [mysql]> show databases;    
+--------------------+
| Database           |
+--------------------+
| aaa                |
| aab                |
| aac                |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
6 rows in set (0.004 sec)



MariaDB [mysql]> drop database aaa;    # 删库
Query OK, 0 rows affected (0.003 sec)

MariaDB [mysql]> show databases;
+--------------------+
| Database           |
+--------------------+
| aab                |
| aac                |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
5 rows in set (0.001 sec)


综合练习

请添加图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/494716.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

使用@PropertySource加载配置文件

1.PropertySource和PropertySources注解 1.1.PropertySource注解概述 PropertySource注解是Spring 3.1开始引入的配置类注解。通过**PropertySource注解可以将properties配置文件中的key/value存储到Spring的Environment中,Environment接口提供了方法去读取配置文…

ModStartCMS v6.3.0 电脑端在线充值,前端库升级

ModStart 是一个基于 Laravel 模块化极速开发框架。模块市场拥有丰富的功能应用,支持后台一键快速安装,让开发者能快的实现业务功能开发。 系统完全开源,基于 Apache 2.0 开源协议,免费且不限制商业使用。 功能特性 丰富的模块市…

AMA 回顾|关于访问水晶铸造的一些调整建议

这是社区系列 AMA 的第一期。下周,我们将举行一场新的 AMA,讨论重新启动游戏的相关内容。 感谢大家在百忙之中参与这次活动。相信社区的每一位成员都在蓝精灵协会这个项目中投资了一些东西,比如时间、精力或者是金钱。蓝精灵协会团队在过去的…

docker打包流程

docker打包流程 1、使用docker前置准备: 电脑下载docker桌面版,以及开启虚拟机步骤:https://blog.csdn.net/qq_34905631/article/details/126573826下载docker桌面版 :https://docs.docker.com/desktop/install/windows-install…

swagger-codegen智能生成Python-unittest测试用例

简介:Swagger Codegen是一个开源项目,用于从OpenAPI规范(以前称为Swagger规范)文件生成服务器存根、客户端库和API文档。它支持多种编程语言和框架,包括Python、Java、Ruby、Go等。 历史攻略: sanic&…

快速打造高效代驾服务:代驾系统源码分享

要想快速打造高效代驾服务,选择一款优秀的代驾系统是非常重要的。本文介绍的代驾系统源码是基于PHP语言和MySQL数据库开发的,可以轻松地在Linux或Windows系统中部署。 首先,需要确保服务器环境符合系统的要求,包括PHP版本、MySQL版…

三范式(详解+例子)

第一范式(1NF):每一列都是不可分割的原子数据项(什么意思,每一项都不可分割,像下面的表格就能分割,所以它连第一范式都算不上) 分割后的样子 (它就是第一范式了&#xff…

crm项目bug小结

项目主要内容分析: 第一天完成了系统用户登录、退出、密码修改、全局异常、非法请求与记住我等系统基本功能。 项目的目录结构如图: 1 登录思路: ** * 1.参数校验 * 用户名 非空 * 密码 非空 * 2.根据用户名 查询用户记录 * 3.校验用户存…

搞懂 API ,API 中 URI 设计规范分享

API(Application Programming Interface)是现代软件开发中的一项关键技术,它为不同应用程序间提供了数据和功能交互的标准化方式。而 URI(Uniform Resource Identifier)作为 API 中的重要部分,其规范和良好…

BigCode开放性能超越Copilot的代码生成模型Starcoder

BigCode释出高效能程式码生成模型StarCoderBase,与为Python调校的StarCoder,效能超越GitHub Copilot初期版本所用的OpenAI code-cushman-001模型: BigCode昨晚发布了基于源代码和自然语言文本训练的编程语言生成模型StarCoder。其训练数据包…

JavaSE基础(五)—— 方法(定义、调用、重载)、return关键字

目录 一、方法定义、调用 1. 方法完整的定义形式、调用 2. 方法的其他定义形式、调用 二、方法使用的常见问题 三、方法案例 1. 定义方法的技巧、计算 1- n的和返回 2. 数组求最值案例改方法形式 四、方法调用的内存图 五、方法的参数传递机制 基本类型和引用类型的参…

携带信息的Ajax GET请求

前端页面代码&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>ajax get请求</title><script type"text/javascript">window.onload function () {document.getEle…

Spring管理数据库事务

Spring编程式事务和声明式事务的验证 1、工程目录pom.xml 2、在resources目录创建配置文件applicationContext_1.xmlapplicationContext_2.xmlapplicationContext_3.xmljdbc.properties 3、创建数据表accountaccount 4、创建dao类5、创建service类6、创建测试类7、实验结果图1 …

基于python的点云处理库总结

想对于PCL&#xff0c;python处理点云的库还是比较多的&#xff0c;下面对此进行简单的总结&#xff1a; 一、Open3D A Modern Library for 3D Data Processing&#xff0c;Intel出品&#xff0c;MIT协议。 Open3D是一个支持3D数据处理软件快速开发的开源库。Open3D使用C和P…

CSS - 垂直菜单(鼠标移入时显示右侧容器)

效果图 示例源码 <body><section class="content"><ul class=

OpenVINO 2022.3之四:OpenVINO模型转换

OpenVINO 2022.3之四&#xff1a;OpenVINO模型转换 OpenVINO 2022.3 支持的模型格式: OpenVINO IR&#xff08;中间表示&#xff09; - OpenVINO™的专有格式&#xff0c;可以完全利用其全部功能。 ONNX和PaddlePaddle - 直接支持的格式&#xff0c;这意味着它们可以在OpenVI…

DT7遥控DBUS协议解析

文章目录 运行环境&#xff1a;1.1 DBUS协议解析1)DT7遥控2)配置串口引脚3)配置串口接收DMA 2.1例程代码移植1)例程移动到 Inc 和 Src2)makefile添加.c文件 3.1核心代码解释4.1代码修改1)bsp_rc.c 和 remote_control.c2)调用代码 5.1调试1)硬件接线2)串口工具监视拨杆数据 运行…

【C进阶】-- 字符串函数(1)

目录 0. 前言 1. 函数介绍 1.1 strlen 1.1.1主动改变\0的位置 ✅"strlen函数的返回类型是size_t - 无符号整型"✅ 当使用strlen函数但不引用头文件时&#xff0c;执行结果超出预料: 求字符串长度的方法&#x1f4a5; 1.计数器 2.递归 3.指针 - 指针 1.2 st…

HBase安装下载与集群(高可用)

一、准备 1.1 安装zookeeper zookeeper 安装下载与集群 1.2 安装HADOOP hadoop搭建集群搭建 1.3下载HBase https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/ 二、正常部署 2.1 检查是否正常启动 2.2解压 tar -zvxf hbase-2.4.11-bin.tar.gz2.3配置环境变量 vim /…

高效的工作团队都在使用什么工具?

、 移动互联网时代&#xff0c;企业需要开源节流&#xff0c;需要提高员工整体工作效率。尤其对于互联网公司来说&#xff0c;要快速发展业务&#xff0c;更需要让团队工作简单、方便、高效。然而大多公司都面临以下低效阻碍&#xff1a;跨公司、跨部门沟通合作困难。不同部门和…