安装
查询出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用户和自己设置的密码远程连接数据库了