CentOS7下mysql安装

这篇博客详细介绍了如何在CentOS系统上安装MySQL 5.7,包括下载安装包、卸载旧版本、安装各组件以及启动和配置MySQL服务。随后,通过`mysql_secure_installation`命令初始化数据库,并设置了root用户的密码。接着,通过修改配置文件和授权,实现了MySQL的远程连接。最后,开启了3306端口并调整了防火墙规则,确保远程访问的畅通。
摘要由CSDN通过智能技术生成

一、安装

CentOS安装
官网下载安装命令:

下载地址:

https://downloads.mysql.com/archives/community/

解压文件

tar -xf mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar

安装关系包:

 yum search perl
 yum -y install perl.x86_64

卸载其他版本的mysql-libs包

yum remove mysql-libs

安装 MySQL5.7.27

# 安装 mysql-community-client
rpm -ivh mysql-community-common-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.27-1.el7.x86_64.rpm
# 安装 community-server
rpm -ivh mysql-community-server-5.7.27-1.el7.x86_64.rpm

# 其他包安装(选装)
rpm -ivh mysql-community-embedded-devel-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-test-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-5.7.27-1.el7.x86_64.rpm

二、安装后配置

1、启动mysqld服务
systemctl start mysqld
systemctl enable mysqld
2、查看初始密码
cat /var/log/mysqld.log |grep root@localhost
2、初始化
root@ubuntue:~# 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 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 plugin?    # 要安装验证密码插件吗?

Press y|Y for Yes, any other key for No: N    # 这里我选择N
Please set the password for root here.

New password:   # 输入要为root管理员设置的数据库密码

Re-enter new password:   # 再次输入密码


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     # 删除匿名账户
Success.


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) : N    # 禁止root管理员从远程登录,这里我没有禁止

... skipping.
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数据库并取消对它的访问权限
- Dropping test database...
Success.

- Removing privileges on test database...
Success.

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   # 刷新授权表,让初始化后的设定立即生效
Success.

All done!
2、设置远程连接

第一步:修改配置文件的端口绑定(centos中无法使用)

root@ubuntue:~# vim /etc/mysql/mysql.conf.d/mysqld.cnf
注释:# bind-address = 127.0.0.1

第二步:修改访问权限

root@ubuntue:~# mysql -u root -p

mysql> set global validate_password_policy=0;
mysql> grant all privileges on *.* to 'root'@'%' identified by 'password'; # 修改密码
mysql> flush privileges;

mysql> grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;

mysql> flush privileges;

mysql> exit;

第三步:重启mysql

root@ubuntue:~# systemctl restart mysqld

第四步:开启3306端口

systemctl start firewalld  # 启动friewall

systemctl status firewalld # 查看firewall启动情况

firewall-cmd --zone=public --add-port=3306/tcp --permanent   # 开启3306端口

firewall-cmd --reload # 配置立即生效

firewall-cmd --zone=public --list-ports # 查看防火墙所有开放的端口

firewalld # firewall-cmd --reload 重启

firewall-cmd --query-port=3306/tcp # 查看3306端口是否开启

查看端口:

root@ubuntue:~# netstat -anp | grep mysql

kill -9 6832 # 终止端口

设置若还无法连接请配置服务器防火墙3306端口

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值