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

相关推荐
yeflx11 分钟前
Ubuntu22.04安装Mysql Workbench
数据库·mysql·adb
PaperData12 分钟前
1986-2025年《中国能源统计年鉴》全年份pdf+excel版
数据库·能源
夜雪一千16 分钟前
MySQL 自增 ID 的底层原理与坑点
android·mysql·adb
SelectDB技术团队24 分钟前
日志场景 Elasticsearch 替换实操:建表、索引、写入链路与查询改写的完整参数
大数据·数据库·数据仓库·elasticsearch·全文检索·日志分析·apache doris
百数平台30 分钟前
低代码安全技术实践:表单 / 流程 / 报表三级权限体系设计解析
java·大数据·数据库
驭渊的小故事34 分钟前
MyBatis-Plus 实战指南:从基础 CRUD 到条件构造器与自定义 SQL(二)
数据库·sql·mybatis
小小AK37 分钟前
销售订单从 CRM 推到 ERP:一条策略的完整同步实战
数据库
木雷坞39 分钟前
Docker Compose部署Docmost:数据库、附件持久化与首次协作
数据库·docker·容器
VidDown42 分钟前
上线三个月后的第一次事故:一个 Django 服务的日志、监控与故障复盘
数据库·python·django·wpf·音视频·视频编解码
小蒜学长1 小时前
基于Springboot+Vue的高校教师教学业绩综合管理系统的设计与开发(代码+数据库+LW)
java·数据库·spring boot·后端·教学业绩管理·三级权限