【CentOS8】yum安装mysql数据库

yum安装mysql数据库并设置远程访问

安装

查询出yum库中所有的mysql

// 查询
yum -y list mysql*

// 查询结果
Last metadata expiration check: 0:03:04 ago on Fri 19 Aug 2022 10:03:53 AM CST.
Available Packages
mysql.x86_64                                                                              8.0.26-1.module_el8.4.0+915+de215114                                                                       appstream
mysql-common.x86_64                                                                       8.0.26-1.module_el8.4.0+915+de215114                                                                       appstream
mysql-devel.x86_64                                                                        8.0.26-1.module_el8.4.0+915+de215114                                                                       appstream
mysql-errmsg.x86_64                                                                       8.0.26-1.module_el8.4.0+915+de215114                                                                       appstream
mysql-libs.x86_64                                                                         8.0.26-1.module_el8.4.0+915+de215114                                                                       appstream
mysql-selinux.noarch                                                                      1.0.5-1.el8                                                                                                appstream
mysql-server.x86_64                                                                       8.0.26-1.module_el8.4.0+915+de215114                                                                       appstream
mysql-test.x86_64

安装mysql

// 安装mysql ---> mysql.x86_64 是上面查询出来的版本
yum install -y mysql.x86_64

// 安装mysql服务 ---> mysql-server.x86_64 也是上面查询出来的版本
yum install -y mysql-server.x86_64

启动mysql

// 启动mysql服务
service mysqld start

// 设置开机自启
chkconfig mysqld on

设置远程访问

连接mysql

// 使用root用户连接mysql 默认密码是空,直接回车即可登录
// 使用root用户连接mysql 默认密码是空,直接回车即可登录
// 使用root用户连接mysql 默认密码是空,直接回车即可登录(重要的事情说三遍)
// 命令: mysql -uroot -p
[root@VM-12-2-centos /]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

修改密码

// 选择数据库
use mysql;

// 连接到mysql以后, 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

// 改密码后,刷新权限
flush privileges;

设置远程访问

// 需要先选择mysql数据库
// use mysql;

// 设置远程访问
update user set host = '%' where user = 'root';

// 刷新权限
flush privileges;

到这里就可以通过root用户和自己设置的密码远程连接数据库了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值