MySQL学习-如何在CentOS 8 安装MySQL 8.0 设置远程登陆

安装MySQL8.0

1、使用新的包管理器安装MySQL
[root@localhost ~]# sudo dnf install @mysql
2、验证是否成功,命令
[root@localhost ~]# mysql -V

显示如下

mysql  Ver 8.0.17 for Linux on x86_64 (Source distribution)
3、设置开机自启动
[root@localhost ~]# sudo systemctl enable --now mysqld
4、查看是否运行
[root@localhost ~]# sudo systemctl status mysqld

显示如下信息:

● mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-04-06 14:39:44 CST; 36s ago
  Process: 28099 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 27972 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
  Process: 27947 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 28056 (mysqld)
   Status: "Server is operational"
    Tasks: 39 (limit: 23825)
   Memory: 537.3M
   CGroup: /system.slice/mysqld.service
           └─28056 /usr/libexec/mysqld --basedir=/usr

4月 06 14:39:36 localhost.localdomain systemd[1]: Starting MySQL 8.0 database server...
4月 06 14:39:36 localhost.localdomain mysql-prepare-db-dir[27972]: Initializing MySQL database
4月 06 14:39:44 localhost.localdomain systemd[1]: Started MySQL 8.0 database server.

Active: active (running) 表示正在运行

5、添加密码及安全设置
[root@localhost ~]# sudo mysql_secure_installation

出现如下信息:

这里总结:

  • 要求你配置VALIDATE PASSWORD component(验证密码组件): 输入y ,回车进入该配置
  • 选择密码验证策略等级, 我这里选择0 (low),回车
  • 输入新密码两次
  • 确认是否继续使用提供的密码?输入y ,回车
  • 移除匿名用户? 输入y ,回车
  • 不允许root远程登陆? 需要远程登陆,所以输入n ,回车
  • 移除test数据库? 输入y ,回车
  • 重新载入权限表? 输入y ,回车
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT 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 component?

Press y|Y for Yes, any other key for No: y  (要求你配置VALIDATE PASSWORD component(验证密码组件),输入y,回车)

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 (选择密码验证策略等级, 选择0 ,回车)
Please set the password for root here.

New password:    (你的新密码,回车)

Re-enter new password:   (再一次你的新密码,回车)

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : 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. 


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远程登陆? 需要远程登陆,所以输入n ,回车)

 ... 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数据库? 输入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  (重新载入权限表? 输入y ,回车)
Success.

All done!
6、配置远程登陆

上面步骤中设置的密码

[root@localhost ~]# mysql -uroot -p

使用 mysql数据库

mysql> use mysql;

更新root用户登录地址

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

权限刷新

mysql> flush privileges;

退出

mysql> exit;
7、开启防火墙端口

添加3306端口号

[root@localhost ~]# sudo firewall-cmd --add-port=3306/tcp --permanent

防火墙重载配置

[root@localhost ~]# sudo firewall-cmd --reload
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值