Securing MySQL Server - setup root password

WSL 安装 MySQL 安装 apt 库有现成的包,直接执行命令安装 sudo apt install mysql-server 配置 执行以下命令 sudo mysql_secure_installation 可能会出现以下报错: Securing the MySQL server deployment. Enter password for user root: Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysql 阅读详情
 

Securing MySQL Server - setup root password

<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script>

As you see MySQL server connects without any password restriction. This is not a good idea for production environment so let us setup root password with mysqladmin command. By default MySQL server installs without any password and it use root account as admin user for managing MySQL server. Please do not get confused with FreeBSD root user account. Both are different account and password for both accounts should be different for security reasons.

$ mysqladmin -u root password MYPASSWORD

Now try to connect server:

$ mysql

Output:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

To connect to MySQL server use following syntax (when prompted for password type newly set password):

$ mysql -u root -p

Output

Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 4 to server version: 5.0.9-beta

Type 'help;' or '/h' for help. Type '/c' to clear the buffer.

mysql>

Now your server is secured and no one can connect to MySQL server anonymously.
See also:

Securing MySQL Server - setup root password

As you see MySQL server connects without any password restriction. This is not a good idea for production environment so let us setup root password with mysqladmin command. By default MySQL server installs without any password and it use root account as admin user for managing MySQL server. Please do not get confused with FreeBSD root user account. Both are different account and password for both accounts should be different for security reasons.

$ mysqladmin -u root password MYPASSWORD

Now try to connect server:

$ mysql

Output:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
To connect to MySQL server use following syntax (when prompted for password type newly set password):

$ mysql -u root -p

Output
Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 4 to server version: 5.0.9-beta

Type 'help;' or '/h' for help. Type '/c' to clear the buffer.

mysql>
Now your server is secured and no one can connect to MySQL server anonymously.
See also:
Ubuntu安装MySQL 8.0:官方仓库部署与安全加固全指南 在Linux服务器环境中,数据库的部署与配置是后端开发与运维的核心基础。MySQL作为最流行的开源关系型数据库,其安装过程不仅涉及软件包管理,更关系到后续的系统安全与性能表现。理解APT软件源的工作原理,能帮助开发者选择官方仓库获取最新版本,确保获得及时的安全更新与功能优化。通过运行mysql_secure_installation脚本进行安全初始化,是遵循最小权限原则、移除匿名用户、禁用root远程登录的关键步骤,能有效构建生产环境的安全基线。本文以Ubuntu 22.04/24.04 LTS为背景,详细 阅读详情

相关推荐

Ubuntu 20.04 安装配置 MySQL 8.0 全指南:auth_socket 认证与 utf8mb4 设置

MySQL 是 Linux 环境下最主流的关系型数据库,其安装与配置涉及用户认证机制、字符集编码、网络监听策略等核心原理。在 Ubuntu 20.04 这一长期支持系统中,MySQL 默认采用 auth_socket 插件实现免密本地认证,虽提升安全性但导致 Navicat、PHP 等标准客户端连接失败;同时默认字符集为不兼容 emoji 的旧式 utf8,须显式升级为 utf8mb4 才能保障中文及生僻字正确存储。这些设计差异直接影响开发联调、课程部署与生产上线。本文聚焦 Ubuntu 20.04 系统特

dfdfadsf3443的博客 368

ubuntu下安装mysql问题汇总

apt安装完mysql后,用mysql_secure_installation设置总是提示 Securing the MySQL server deployment. Enter password for user root: Error: Access denied for user 'root'@'localhost' mysql5.7以后,增加的安全机制,默认有个root的密码,但是apt直接安装的,并不清楚这个东西 解决方法,直接 sudo mysql_secure_installation

weixin_43262264的博客 1857

Mysql的安全配置向导命令mysql_secure_installation

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30...

sinat_27272423的专栏 840

对于腾讯云服务器无法安装Mysql的解决方式

对于腾讯云服务器无法安装Mysql的解决方式 下面是我在通过网上搜索方法无效果后。采用官方的解决文档来进行的安装与使用 ,在此我只是做个人记录。 1.下载并添加存储库 sudo yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm 2.安装MySQL 8.0包 与其他使用yum的软件包一样安装MySQL: yum install mysql-community-serv

NicolasLearner的博客 1191

MySQL使用

0. 前言 。。。 1. 安装MySQL Ubuntu上直接通过apt-get安装 sudo apt-get install mysql-server 启动服务 sudo service mysql start 停止服务 sudo service mysql stop 初始化配置 sudo mysql_secure_installation 配置选择 (base) kangxiatao@AnoI:~$ sudo mysql_secure_installation Securing the MySQL

kangxiatao的博客 246

Ubuntu 18.04安装MySQL 5.7详细教程:从apt配置到安全加固

MySQL是关系型数据库的基石,其安装与配置涉及包管理、服务启动、字符集、权限控制等核心概念。在Ubuntu系统中,apt源机制决定了默认安装的是经OS厂商验证的稳定版本(如18.04对应MySQL 5.7),而非最新版;理解apt-cache policy、apt update的元数据同步原理及mysql_secure_installation的安全加固逻辑,是保障数据库可用性与生产安全的关键。本文聚焦真实运维场景,覆盖磁盘内存检查、bind-address配置、utf8mb4字符集统一、应用专用用户创建

weixin_34326179的博客 452

Ubuntu 20.04 安装 MySQL 8.0 后无法登录的完整排障指南

MySQL 是一种关系型数据库管理系统(RDBMS),其核心原理包括客户端-服务器架构、基于插件的认证机制与严格的权限模型。在 Ubuntu 20.04 系统中,MySQL 8.0 默认采用 auth_socket 插件实现操作系统级身份认证,而非传统密码验证,这一设计显著提升了本地安全性,但也导致普通用户执行 mysql -u root -p 时必然失败。该机制的技术价值在于规避密码明文传输与存储风险,适用于开发环境下的 root 管理隔离;典型应用场景涵盖 PHP/Laravel 本地开发、Django

cuiyingchan0663的博客 426

MySQL 集群技术 1.源码编译与部署

本文介绍了在Linux系统上通过源码编译方式部署MySQL 8.3的完整流程。主要内容包括:下载MySQL源码包、安装编译依赖工具(如cmake、gcc等)、配置编译参数(指定安装路径、数据目录、字符集等)、执行make编译和安装。部署阶段涉及设置环境变量、创建配置文件、初始化数据库、设置root密码及安全加固(删除匿名用户、禁止root远程登录等)。该过程适合企业生产环境部署,需要较长时间编译并确保服务器配置足够。

pengxiaolin_yi的博客 68

Ubuntu 18.04 手搭 LAMP 环境:Apache+MySQL+PHP 原生部署指南

LAMP 是 Linux、Apache、MySQL 和 PHP 四组件构成的经典 Web 开发栈,代表一种透明、可控、可调试的基础服务架构。其核心原理在于请求由 Apache 接收后,通过模块(如 mod_php)交由 PHP 解析,再经 MySQL 驱动完成数据交互,全程依赖系统级配置与进程协作。该技术栈具备极强的教学价值与工程可追溯性,广泛应用于教学环境、遗留系统维护及轻量级生产部署。尤其在 Ubuntu 18.04 这类长期稳定发行版中,原生源提供的 Apache 2.4.29、MySQL 5.7.3

weixin_30919429的博客 601

Rocky Linux 8.10 二进制安装 MySQL 8.0.28

软件包:mysql-8.0.28-linux-glibc2.12-x86_64.tar。

一直在努力学习的菜鸟 290

Ubuntu 18.04 手动部署 LAMP 全流程:原理、安全与排障实战

LAMP(Linux + Apache + MySQL + PHP)是 Web 服务最基础的运行栈,其核心在于理解请求处理链路、进程模型与配置驱动机制。Apache 的模块化加载、MySQL 的认证插件与权限体系、PHP 的 SAPI 模式(如 mod_php)共同构成动态 Web 服务的底层逻辑。掌握这些原理不仅支撑 WordPress 等传统 CMS 部署,更奠定容器化、HTTPS 化及监控告警等进阶能力的基础。在 Ubuntu 18.04 这一稳定长周期发行版上手动安装,能深度暴露依赖关系、配置颗粒度

342

mysql安全安装

mysql安装完成后,使用mysql_secure_installation命令进行安全性安装设置 mysql_secure_installation Securing the MySQL server deployment. Enter password for user root:这里输入用户密码The ‘validate_password’ component is installed on the server.The subsequent steps will run with the exi

qq_33246702的博客 1127

ubuntu安装 mysql并远程访问

Ubuntu18.04 安装MySQL_Weison-CSDN博客_ubuntu 安装mysql tu:~# sudo mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It ch..

sun007700的专栏 1172

Ubuntu 18.04 安装mysql

1. 测试是否安装过mysql: sudo dpkg -l |grep mysql 若没有安装,则显示为空。 2. 安装命令: sudo apt install mysql-server 安装成功后,mysqld自动启动,可使用ps命令查看是否安装成功: ubuntu@VM-12-10-ubuntu:~$ ps -ef |grep mysql mysql 4801 1 0 16:15 ? 00:00:00 /usr/sbin/mysqld --daemoniz

luckwsm的专栏 309

mac 安装mysql

mac 安装mysql 1. 安装homebrew 2. 用brew 安装mysql 执行brew install mysql,会出现类似的提示: We've installed your MySQL database without a root password. To secure it run: mysql_secure_installation MySQ...

kkx的博客 595

[Mac] 记录使用Homebrew安装Mysql全过程

macOS Sierra下使用Homebrew安装Mysql记录

lkxlaz的博客 4万+

【Ubuntu】在Ubuntu server中安装mysql

在ubuntu系统中安装mysql数据库,相对简单一些,主要的步骤如下: 1. 先查看是否有mysql安装,执行如下命令: dpkg -l | grep mysql 如果没有安装mysql则不会有内容显示。 2. 执行mysql 安装的shell命令: sudo apt-get install mysql-server # 如果是root用户登录则可以省略掉sudo 等待执行完毕即可。 3. ...

qgnczmnmn的博客 2006

Ubuntu 22.04 安装mysql数据库并且实现远程Navicat连接教程(转载)

Ubuntu 22.04 安装mysql数据库并且实现远程Navicat连接教程(转载)

weixin_42077793的博客 6766
上一篇: How to Reset the Root Password
下一篇: HOWTO: FreeBSD with CCACHE
striker
博客等级 码龄25年 10粉丝 56原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值