当前位置: 首页 > news >正文

ubuntu安装mysql

安装

sudo apt-get update
sudo apt-get install mysql-server mysql-client

初始化数据库

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

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) : No

 ... 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) : No

 ... 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! 

 

密码设置

-- 使用默认的认证方式
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;

卸载mysql

如果安装配置出问题,使用此命令卸载后重新安装。否则生成的文件可能不全。

sudo apt-get autoremove mysql* --purge


 

修改/查看密码强度

    修改

mysql>  set global validate_password.policy=0; #设置密码强度为最低
mysql>  set global validate_password.length=6; # 设置密码长度为0 
 

    查看密码强度

mysql> SHOW VARIABLES LIKE 'validate_password%';

 

忘记密码


在[mysqld]的段中加上一句:skip-grant-tables保存并退出
vim /etc/my.cnf
[mysqld]
......
skip-grant-tables

systemctl restart mysqld.service mysql -u root
use mysql;
update user set authentication_string='' where user='root';
exit;

屏蔽 skip-grant-tables:vim /etc/my.cnf,在skip-grant-tables前面添加# 

systemctl restart mysqld.service 
mysql -u root
use mysql;
update user set host='%' where user='root'; 
FLUSH PRIVILEGES;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
FLUSH PRIVILEGES;

 

http://www.hskmm.com/?act=detail&tid=33236

相关文章:

  • 计算机视觉技术与应用深度解析
  • AGC 板刷记录1
  • 2025.10.17总结
  • 记Windows 11环境Rust下载安装配置流程
  • K8s学习笔记(九) job与cronjob - 教程
  • [HZOI]CSP-S模拟33
  • [PaperReading] VLM2Vec-V2: Advancing Multimodal Embedding for Videos, Images, and Visual Documents
  • ShandongCCPC2024
  • 标悬浮展开多级菜单
  • Nimble:让SwiftObjective-C测试变得更优雅的匹配库 - 指南
  • 2025.10.17总结 - A
  • Ubuntu创建python桌面图标
  • 深入解析Pure恶意软件家族:从RAT到构建器再到开发者
  • Ubuntu上配置Flask应用程序的Nginx和uWSGI
  • 实验一 现代c++基础课程
  • 平均融资利率求法及ORACLE语法解析
  • [Linux]如何列出被软链接的文件,列出被链接位置
  • 10.13课后作业
  • 【Linux】基础 I/O - 指南
  • 不情愿算法学概论
  • DIVCNT
  • 3. JVM 运行时数据区
  • 软工学习日志
  • Pixelium Design:Vue3 的像素风 UI 组件库
  • 修电脑不求人:AI智能修复电脑工具的体验分享
  • 效率与安全双升:AI许可证识别重塑医药行业合规流程
  • Spring BeanPostProcessor 前置处理 afterPropertiesSet BeanPostProcessor 后置处理区别
  • Xcode上编译调试ffmpeg - 详解
  • 最新版Origin 2025b安装包下载及详细安装教程,附永久免费中文汉化破解版Origin安装包
  • 第十七篇