Liunx 安装Mysql

前言:本次安装使用的版本是Mysql4.7

该安装文档参考阿里云提供的mysql安装方式

更新YUM源

wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
sudo yum install -y mysql57-community-release-el7-10.noarch.rpm
sudo yum install -y mysql-community-server --nogpgcheck

查看MySQL版本号

mysql -V

当出如下内容,mysql安装完成,接下来进行一些相关配置

[root@iZwz9c9nwvs5wt2h9n5cpnZ /]# mysql -V
mysql  Ver 14.14 Distrib 5.7.44, for Linux (x86_64) using  EditLine wrapper

启动MySQL并设置开机启动MySQL

sudo systemctl start mysqld
sudo systemctl enable mysqld
sudo systemctl daemon-reload

获取MySQL的初始密码

sudo grep "password" /var/log/mysqld.log

m3?z1qf1wCfp 这个是本次mysql安装后的初始化密码

[root@iZwz9c9nwvs5wt2h9n5cpnZ /]# sudo grep "password" /var/log/mysqld.log
2023-12-30T14:18:07.620969Z 1 [Note] A temporary password is generated for root@localhost: m3?z1qf1wCfp

配置MySQL的安全性

mysql_secure_installation
Securing the MySQL server deployment.

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

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使用新密码。

输入Y删除匿名用户账号。

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  #是否删除匿名用户,输入Y
Success.

输入Y禁止root账号远程登录。

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) : Y #禁止root远程登录,输入Y
Success.

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

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) : Y #是否删除test库和对它的访问权限,输入Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

输入Y重新加载授权表。

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 #是否重新加载授权表,输入Y
Success.

All done!

Mysql安装完毕

此外记得在服务器安全组开启3306端口

常见错误

问题1

navicat 添加mysql数据库连接 点击测试连接报:is not allowed to connect to this mysql server

出现这种情况的原因是因为:mysql数据库只允许自身所在的本机器连接,不允许远程连接。

进入服务器数据输入如下命令

mysql -u root -p

use mysql;

select host from user where user='root';

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

刷新配置

flush privileges;

接下来使用navicat 再次点击测试连接 提示连接成功

退出mysql交互页面 返回Liunx终端

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值