首页 > 数据库 >mysql学习笔记1

mysql学习笔记1

时间:2024-09-23 16:52:14浏览次数:1  
标签:database 数据库 mysql 笔记 学习 MySQL test password

安装

1.更新

sudo apt update

2.安装

$ sudo apt install mysql-server

3.查看运行状况

$ sudo systemctl status mysql.service 
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
     Active: active (running) since Mon 2024-09-23 16:13:22 CST; 48s ago
    Process: 3135 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=e>
   Main PID: 3143 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 1917)
     Memory: 366.0M
        CPU: 980ms
     CGroup: /system.slice/mysql.service
             └─3143 /usr/sbin/mysqld

Sep 23 16:13:21 iZbp15gacvms2qkuahiq0oZ systemd[1]: Starting MySQL Community Se>
Sep 23 16:13:22 iZbp15gacvms2qkuahiq0oZ systemd[1]: Started MySQL Community Ser>

4.运行安全脚本

$ sudo mysql_secure_installation 

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: 

输入y,选择启用并设置密码验证组建。

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 
```bash
有三个级别的密码验证策略:
    LOW:长度至少为 8 个字符。
    MEDIUM:长度至少为 8 个字符,并且包含数字、大小写字母和特殊字符。
    STRONG:长度至少为 8 个字符,并且包含数字、大小写字母、特殊字符,并且不在字典文件中。
输入 0 1 2分别代表低 中 高 三档。 `1`
```bash
Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information.

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : 

询问是否需要移除匿名用户。 y

Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : 

是否禁止root用户远程登陆 n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No)

是否删除 test 数据库 n

... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : 

是否重新加载权限表使设置生效?y

Success.

All done! 

至此,安装完成。

试运行

1.登陆

$ sudo mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.39-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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> 

指令中-u代表-user,登陆用户为root-p代表-password,输入密码

2.查看现有数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

show databases列出mysql服务器上所有数据库。
information_schema:这是一个系统数据库,提供了关于所有其他数据库的信息。
mysql:这是 MySQL 系统数据库,存储了用户账户、权限和其他系统级别的信息。
performance_schema:这是一个性能模式数据库,用于监控 MySQL 服务器的性能。
sys:这是一个系统数据库,提供了一组视图和过程,帮助分析 MySQL 性能。

3.创建一个数据库

mysql> create database test_database;
Query OK, 1 row affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test_database      |
+--------------------+
5 rows in set (0.00 sec)

使用create database + 数据库名 可以新建数据库。

4.选择一个数据库

mysql> use test_database 
Database changed
mysql> select database();
+---------------+
| database()    |
+---------------+
| test_database |
+---------------+
1 row in set (0.00 sec)

使用use进行数据库选择,再使用select database();进行查看已选择的对象。

5.退出

mysql> quit
Bye

或者

mysql> exit
Bye

标签:database,数据库,mysql,笔记,学习,MySQL,test,password
From: https://www.cnblogs.com/PrepAndPonder/p/18427250

相关文章

  • 《测度论与概率论基础》笔记 1.3.2
    《测度论与概率论基础》笔记1.3.21.3\(\sigma\)域的生成定理1.3.2  本文是程士宏老师的《测度论与概率论基础》这本书的读书笔记。这本书算是国内为数不多的较为不错的测度论教材之一,但是很多地方讲述不详细,这里进行补充。定理1.3.2:如果\(\mathscr{Q}\)是半环,其生成的......
  • 《测度论与概率论基础》笔记 1.3.1
    《测度论与概率论基础》笔记1.3.11.3\(\sigma\)域的生成本文是程士宏老师的《测度论与概率论基础》这本书的读书笔记。这本书算是国内为数不多的较为不错的测度论教材之一,但是很多地方讲述不详细,这里进行补充。定理1.3.1详细理解书中的命题1.3.1说:由任意集合系\(\mathscr......
  • 基于Node.js+vue云笔记设计(开题+程序+论文) 计算机毕业设计
    本系统(程序+源码+数据库+调试部署+开发环境)带文档lw万字以上,文末可获取源码系统程序文件列表开题报告内容研究背景在信息爆炸的时代,个人知识管理与日常信息记录成为了现代人不可或缺的一部分。传统的笔记方式,如纸质笔记本或简单的文本文件,已难以满足人们对高效、便捷、跨......
  • 网络流学习记录
    CCPC网络赛GProblemG.疯狂星期六Inputfile:standardinputOutputfile:standardoutputTimelimit:1secondMemorylimit:256megabytesyyq和他的朋友们一共n个人(编号为1到n,yyq编号为1)去某饭店吃疯狂星期六。第i个人初始手中有ai元的零......
  • MySQL索引
    一.索引是什么MySQL索引是一种数据结构,用于加快数据库查询的速度和性能。大家可以自己试一下有索引和没索引的区别,两者的速度都不是在一个量级上。索引是极大的加快查询数据库的速度。当然,索引这么快也是有代价的,创建索引后会生成索引树,它是占磁盘空间的。磁盘IO是很耗时间......
  • 深度学习经典模型之BERT(下)
    深度学习经典模型之BERT(上)在"深度学习经典模型之BERT(上)"我们描述了BERT基本信息、意义、与GPT和Transformer的区别、预训练、自监督等相关信息后,本章节将介绍BERT的输入、Encoder、微调及两个主流变种。BERTinputs切词方法BERT的切词方法用的是WordPieceembedd......
  • 对比学习
    好的,我们通过一个具体的数字例子来解释c_mi是如何改变顺序的。假设例子假设初始的c_mi是一个形状为(4\times3)的张量(即有4行,3列),值如下:[c_mi=\begin{bmatrix}1&2&3\4&5&6\7&8&9\10&11&12\end{bmatrix}]这个矩阵表示上下文嵌入c,每一......
  • 学习HTMLCSS第六天
    CSS核心属性详解在前端开发中,CSS(层叠样式表)起着至关重要的作用,它可以让网页变得更加美观和易用。本文将详细介绍CSS中的一些核心属性,包括行高、圆角、透明度、颜色值、浮动、定位和子绝父相等。一、行高(line-height)概念:行高是指文本行与行之间的间距,实际上是每行文本......
  • Nat Med.作者提供全文的绘图代码,对于学习作图很有帮助
    本期教程获得本期教程全文代码:在订阅号后台回复关键词:202409232022年教程总汇2023年教程总汇引言今天分享的文章是2024发表在NatMed.期刊中,来自上海交通大学医学院的文章,作者提供了全文的绘图代码,确实勇,对于学习绘图提供充分的素材。也是一个学习作图具重大意义......
  • 如何开启项目管理学习之旅?免费助你建立系统知识体系
    活动介绍新时代新挑战,传统公司的结构、传统的企业管理方式、增长策略与决策面对常态化的不确定性时备受挑战。项目经济时代,面对内外部环境的快速变化,企业、组织、个人要如何从容应对?在当下竞争日益激烈的市场环境中,企业需要不断提升自身管理能力来应对各种挑战,而通过内训系统地学习......