Linux安装Mysql(详细)

安装Mysql数据库

参考阿里云命令安装Mysql

smartservice.console.aliyun.com/service/ser…

安装MySQL

1.远程连接ECS实例。

具体操作,请参见使用VNC登录实例

2.运行以下命令,更新YUM源。

sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm

3.运行以下命令,安装MySQL。

sudo yum -y install mysql-community-server --enablerepo=mysql80-community --nogpgcheck

4.运行以下命令,查看MySQL版本号。

mysql -V

返回结果如下,表示MySQL安装成功。

mysql Ver 8.0.33 for Linux on x86_64 (MySQL Community Server - GPL)

配置MySQL

运行以下命令,启动并设置开机自启动MySQL服务。

sudo systemctl start mysqld
sudo systemctl enable mysqld

运行以下命令,获取并记录root用户的初始密码。

 
sudo grep 'temporary password' /var/log/mysqld.log

执行命令结果示例如下。

2022-02-14T09:27:18.470008Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: r_V&f2wyu_vI

说明

示例末尾的r_V&f2wyu_vI为初始密码,后续在对MySQL进行安全性配置时,需要使用该初始密码。

根据提示信息,重置MySQL数据库root用户的密码。

说明 在输入密码时,系统为了最大限度的保证数据安全,命令行将不做任何回显。您只需要输入正确的密码信息,然后按Enter键即可。

 
Enter password for user root: #输入已获取的root用户初始密码

The existing password for the user account root has expired. Please set a new password.

New password: #输入新的MySQL密码

Re-enter new password: #重复输入新的MySQL密码
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) :Y #输入Y选择更新MySQL密码。您也可以输入N不再更新MySQL密码。

New password: #输入新的MySQL密码

Re-enter new password: #重复输入新的MySQL密码

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :Y #输入Y确认使用已设置的密码。

密码更改的问题

【MySQL】ERROR 1064(42000)

报错原因

MySQL 5.6 之前的版本可以使用set password = password(‘123’)来设置密码, 但是我所用版本是MySQL 8.0.15,要使用set password = ‘123’。

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

密码存在三种校验方式

  1. 强度为LOW:代表密码任意,但长度在8位或以上。
  2. 强度为MEDIUM:代表密码包括:数字、大写字母、小写字母、特殊符号、长度8位以上。
  3. 默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。

我的密码是 121319Tree!@

方法1: 用SET PASSWORD命令

首先登录MySQL。 格式:mysql> set password for 用户名@localhost = password(‘新密码’); 例子:mysql> set password for root@localhost = password(‘123’);

方法2:用mysqladmin

格式:mysqladmin -u用户名 -p旧密码 password 新密码 例子:mysqladmin -uroot -p123456 password 123

方法3:用UPDATE直接编辑user表

首先登录MySQL。 mysql> use mysql; mysql> update user set password=password(‘123’) where user=‘root’ and host=‘localhost’; mysql> flush privileges;

数据库工具连接报错:is not allowed to connect to this mysql server

主要用户Linux安装Mysql之后。window之后连接工具连接

Linux注意开放端口

is not allowed to connect to this MySQL server

服务器上面安装的mysql数据库在本地连接的时候报错:is not allowed to connect to this MySQL server

出现这种情况的原因是因为:

mysql数据库只允许自身所在的本机器连接,不允许远程连接

在mysql所在服务器上面登录进mysql数据库中:

 
mysql -u root -p

image.png

进入到mysql数据库中:

 
use mysql;
select host from user where user='root';

image.png

可以看到 我们执行查询语句得到的数据结果中 host 的值是 localhost

我们执行update语句把权限进行修改

 
update user set host = '%' where user ='root';

然后 刷新配置

 
flush privileges;

image.png

如图所示 可以看到已经修改成功

然后我们再次进行连接

image.png

image.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值