Mysql在线安装及基本操作

更新apt工具

复制代码
sudo apt update  

安装MySQL

复制代码
sudo apt install mysql-server

查看MySQL状态

复制代码
sudo systemctl status mysql

pass@pass:~$ sudo systemctl status mysql

● mysql.service - MySQL Community Server

Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)

Active: active (running) since Tue 2024-03-19 12:27:01 UTC; 17s ago

Main PID: 2649 (mysqld)

Status: "Server is operational"

Tasks: 38 (limit: 4557)

Memory: 365.5M

CGroup: /system.slice/mysql.service

└─2649 /usr/sbin/mysqld

Mar 19 12:27:00 pass systemd1: Starting MySQL Community Server...

Mar 19 12:27:01 pass systemd1: Started MySQL Community Server.

初始MySQL配置

复制代码
sudo mysql_secure_installation

pass@pass:~$ 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: 0

根据提示按照个人需求操作....

以root用户登录,自定义密码

pass@pass:~$ sudo mysql

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

Your MySQL connection id is 10

Server version: 8.0.36-0ubuntu0.20.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>

自定义密码步骤,修改密码等级操作

mysql> SHOW VARIABLES LIKE 'validate_password%';

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

| Variable_name | Value |

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

| validate_password.changed_characters_percentage | 0 |

| validate_password.check_user_name | ON |

| validate_password.dictionary_file | |

| validate_password.length | 8 |

| validate_password.mixed_case_count | 1 |

| validate_password.number_count | 1 |

| validate_password.policy | LOW |

| validate_password.special_char_count | 1 |

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

8 rows in set (0.01 sec)

mysql> set global validate_password.policy=LOW;

Query OK, 0 rows affected (0.01 sec)

mysql> set global validate_password.length =4;

Query OK, 0 rows affected (0.00 sec)

mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'pass';

Query OK, 0 rows affected (0.00 sec)

mysql> exit

Bye

刷新数据库,查看root用户

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> SELECT user,host FROM mysql.user;

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

| user | host |

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

| debian-sys-maint | localhost |

| mysql.infoschema | localhost |

| mysql.session | localhost |

| mysql.sys | localhost |

| root | localhost |

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

5 rows in set (0.00 sec)

mysql> quit;

Bye

相关推荐
hacker70720 小时前
DBeaver Community 鸿蒙 PC 适配全记录:在 HarmonyOS PC 上运行原生数据库管理工具
数据库·华为·harmonyos
长沙三为智能科技20 小时前
⚠️ 内容拦截提示:本次输入含品牌引流型关键词,暂不生成文章
服务器·数据库·oracle
java_logo20 小时前
Docker 部署 MongoDB Community Server:轻松搭建文档数据库平台
数据库·mongodb·docker·nosql·文档数据库·轩辕镜像·mongodb-server
服务端相声演员20 小时前
MySQL的select distinct ..Union all和select..union的区别
数据库·mysql
2501_9304724420 小时前
深度复盘|数据库迁移实战(下):从自建 MySQL 5.7 到腾讯云 MySQL 8.0 的 SQL 兼容改造
数据库·mysql·腾讯云
2501_9304724420 小时前
深度复盘|数据库迁移实战(上):腾讯云助手解析慢查询日志,定位索引缺失与语法不兼容
数据库·阿里云·ffmpeg·云计算·腾讯云·aws
SelectDB技术团队20 小时前
从 ClickHouse 迁移到 Doris:SQL 兼容、同步与验证清单
数据库·人工智能·sql·clickhouse·apache doris·selectdb·湖仓架构升级
leo_messi9420 小时前
Mysql学习(十二) -- SQL执行到底做了什么事?
sql·学习·mysql
敲代码的嘎仔20 小时前
从零实现视频续播 + 学习进度统计:前端心跳、条件更新、GROUP BY 统计全链路拆解
java·前端·数据库·学习·面试·职场和发展·音视频
草莓熊Lotso20 小时前
【Redis 初阶】C++ 客户端实战:从 RESP 协议到 redis-plus-plus 工程化用法
linux·开发语言·网络·数据库·c++·redis·缓存