[centos]安装Mysql 5.7

12 篇文章 0 订阅

mysql安装

以5.7版本为例:

#创建mysql用户
useradd mysql
passwd mysql

# 分配sudo权限
usermod -aG wheel mysql

# 安装mysql
su mysql
sudo wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm
sudo yum update
sudo yum install mysql-server
sudo systemctl start mysqld # 启动mysql
sudo systemctl status mysqld # 查看mysql进程状态
sudo grep 'temporary password' /var/log/mysqld.log #查看首次安装得到的随机密码

安全设置

使用mysql_secure_installation命令进行安全设置,加固内容如下:

  • 设置root密码
  • 去掉匿名用户
  • 删除test数据库
  • 禁止root用户远程登录

示例:

[mysql@localhost ~]$ sudo mysql_secure_installation
[sudo] password for mysql:

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Please set the password for root here.
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
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) : y
Success.

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
 - 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!
[mysql@localhost ~]$

安装问题

  1. 执行sudo mysql_secure_installation提示如下错误:
    Failed! Error: Column count of mysql.user is wrong. Expected 45, found 43. Created with MySQL 50648, now running 50730. Please use mysql_upgrade to fix this error.

修复方式: mysql_upgrade --force -uroot -p

  1. 重置root密码
shell>sudo systemctl stop mysqld
shell>mysqld --skip-grant-tables --skip-networking &
shell>mysql
mysql>FLUSH PRIVILEGES;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
mysql>exit
shell>fg
CRTL + C # 终止程序
shell>sudo systemctl start mysqld

卸载

 sudo yum remove `rpm -aq | grep mysql`
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值