linux 安装并配置MySQL5.7

安装MySQL

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

sudo rpm -Uvh  http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

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

说明:如果提示报错信息No match for argument,您需要先运行命令sudo yum module disable mysql禁用默认的MySQL模块,再安装MySQL。

  sudo yum -y install mysql-community-server --nogpgcheck

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

mysql -V

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

mysql  Ver 14.14 Distrib 5.7.42, for Linux (x86_64) using  EditLine wrapper

4.运行以下命令,启动MySQL。

sudo systemctl start mysqld

5.依次运行以下命令,设置开机启动MySQL。

sudo systemctl enable mysqld
sudo systemctl daemon-reload

配置MySQL

1. 运行以下命令,查看/var/log/mysqld.log文件,获取并记录root用户的初始密码。

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

命令行返回结果如下,其中ARQTRy3+****为MySQL的初始密码。在下一步重置root用户密码时,会使用该初始密码。

 2024-10-10T07:01:26.595215Z 1 [Note] A temporary password is generated for root@localhost: ARQTRy3+****

2.运行以下命令,配置MySQL的安全性。

sudo mysql_secure_installation

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

Securing the MySQL server deployment.

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

b. 设置MySQL的新密码。

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

New password: #输入新密码。长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号包含()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/

Re-enter new password: #确认新密码。
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100 #返回结果包含您设置的密码强度。
Change the password for root ? (Press y|Y for Yes, any other key for No) :Y #您需要输入Y以确认使用新密码。

#新密码设置完成后,需要再次验证新密码。
New password:#再次输入新密码。

Re-enter new password:#再次确认新密码。

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,再次确认使用新密码。

c. 输入Y删除匿名用户。

 Remove anonymous users? (Press y|Y for Yes, any other key for No) :Y
Success.

d. 输入Y禁止使用root用户远程登录MySQL。

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :Y
Success.

e. 输入Y删除test库以及用户对test库的访问权限。

 Remove test database and access to it? (Press y|Y for Yes, any other key for No) :Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

f. 输入Y重新加载授权表。

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :Y Success. 
All done!

更多信息,请参见MySQL文档。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值