mysql安装与修改初始密码

mysql的安装与修改初始化密码


前言

本文使用的ubuntu / loongnix系统,其它系统可参考。


一、mysql的安装

mysql安装:

1、ubuntu系统

sudo apt update
sudo apt install mysql-server

2、loongnix系统

yum update
yum install mysql-devel.loongarch64

mysql启动

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 2020-04-28 20:59:52 UTC; 10min ago
 Main PID: 8617 (mysqld)
 Status: "Server is operational"
 ...

二、修改初始密码

修改密码

sudo mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new-password';
FLUSH PRIVILEGES;

重启mysql

sudo service mysql stop
sudo service mysql start

登录

mysql -u root -p

保护模式

mysql对密码有保护模式如果需要更改,使用下面的方法。
调用不带参数的脚本:

sudo mysql_secure_installation

系统将要求您配置VALIDATE PASSWORD PLUGIN用来测试MySQL用户密码强度并提高安全性的密码:

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

密码验证策略分为三个级别:低,中和强。按下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: 2

在下一个提示符下,将要求您设置MySQL root用户的密码:

Please set the password for root here.


New password: 

Re-enter new password: 

如果您设置了验证密码插件,该脚本将向您显示新密码的强度。键入y以确认密码:

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

以root身份登录

要从命令行与MySQL服务器进行交互,请使用MySQL客户端实用程序,该实用程序是作为MySQL服务器软件包的依赖项安装的。

在MySQL 8.0上,auth_socket默认情况下,root用户通过插件进行身份验证。
该auth_socket插件对localhost通过Unix套接字文件从进行连接的用户进行身份验证。这意味着您不能通过提供密码来以root用户身份进行身份验证。
要以root用户身份登录到MySQL服务器,请输入:

sudo mysql

将为您提供MySQL Shell,如下所示:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.19-0ubuntu5 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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>

如果要使用外部程序(例如phpMyAdmin)以root用户身份登录到MySQL服务器,则有两个选择。

第一个是将身份验证方法从更改auth_socket为mysql_native_password。您可以通过运行以下命令来做到这一点:

mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_password';
mysql > FLUSH PRIVILEGES;

推荐的第二个选项是创建一个新的专用管理用户,该用户可以访问所有数据库:

GRANT ALL PRIVILEGES ON *.* TO 'administrator'@'localhost' IDENTIFIED BY 'very_strong_password';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值