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 systemd[1]: Starting MySQL Community Server...

Mar 19 12:27:01 pass systemd[1]: 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

相关推荐
高兴就好(石2 小时前
DB-GPT部署和试用
数据库·gpt
这孩子叫逆2 小时前
6. 什么是MySQL的事务?如何在Java中使用Connection接口管理事务?
数据库·mysql
Karoku0662 小时前
【网站架构部署与优化】web服务与http协议
linux·运维·服务器·数据库·http·架构
码农郁郁久居人下3 小时前
Redis的配置与优化
数据库·redis·缓存
MuseLss4 小时前
Mycat搭建分库分表
数据库·mycat
Hsu_kk4 小时前
Redis 主从复制配置教程
数据库·redis·缓存
DieSnowK4 小时前
[Redis][环境配置]详细讲解
数据库·redis·分布式·缓存·环境配置·新手向·详细讲解
程序猿小D4 小时前
第二百三十五节 JPA教程 - JPA Lob列示例
java·数据库·windows·oracle·jdk·jpa
Flerken1014 小时前
数据库语言、SQL语言、数据库系统提供的两种语言
数据库·sql·oracle
掘根4 小时前
【网络】高级IO——poll版本TCP服务器
网络·数据库·sql·网络协议·tcp/ip·mysql·网络安全