一、基础配置,设置样本源
[cloud-user@redhat-key ~]$ su - #切换到root用户的主目录
Password:
Last login: Mon Sep 11 20:55:09 EDT 2023 on pts/0
[root@redhat-key ~]# ping qq.com #测试网络连通性
PING qq.com (203.205.254.157) 56(84) bytes of data.
64 bytes from 203.205.254.157: icmp_seq=1 ttl=127 time=61.8 ms
[root@redhat-key ~]# yum clean all # 清空样本源缓存
Loaded plugins: langpacks
Cleaning repos: rhel_dvd rht
Cleaning up everything
[root@redhat-key ~]# cd /etc/yum.repos.d/ # 切换到样本源目录
[root@redhat-key yum.repos.d]# ll # 查看文件
total 8
-rw-r--r--. 1 root root 186 Feb 23 2015 rhel_dvd.repo
-rw-r--r--. 1 root root 210 Feb 23 2015 rht.repo
[root@redhat-key yum.repos.d]# rm -f * # 删除所有文件
[root@redhat-key yum.repos.d]# vi aliyun.repo #新建新的阿里云样本源
[aliyun] #编辑文本文件
name=aliyun
baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck=0
[root@redhat-key yum.repos.d]# yum repolist
二、*(选做)下载失败解决方法
备注(当 repolist下载不成功时,kill占用的pid就可以了)
[root@redhat-key yum.repos.d]# yum repolist
Loaded plugins: langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 1944.
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: yum
Memory : 22 M RSS (413 MB VSZ)
Started: Mon Sep 11 21:15:58 2023 - 11:02 ago
State : Traced/Stopped, pid: 1944
[root@redhat-key yum.repos.d]# kill -9 1944
三、下载、启动、本地登录mariadb(mysql)
[root@redhat yum.repos.d]# yum install -y mariadb-server #下载mysql服务端(服务端包含客户端)
[root@redhat yum.repos.d]# systemctl status mariadb #查看mariadb状态
mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled)
Active: inactive (dead)
[root@redhat yum.repos.d]# systemctl start mariadb #启动第一个disabled
[root@redhat yum.repos.d]# systemctl enable mariadb #启动第二个dead
Ln-s'/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
[root@redhat yum.repos.d]# systemctl status mariadb #查看mariadb状态
mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled)
Active: active (running) since Wed 2023-09-13 23:25:34 EDT; 34s ago
[root@redhat yum.repos.d]# mysql -uroot –p #本地登录mysql
Enter password: #初始密码为空
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
四、设置远程访问步骤
1、防火墙需要放开,添加3306(mysql)端口
2、本地登录修改远程登录权限
MariaDB [(none)]> use mysql; #打开mysql数据库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> show tables; #查看其中有哪些表
MariaDB [mysql]> desc user; #查看user表中的行
MariaDB [mysql]> select host,user,password from user; #查看前三行信息
MariaDB [mysql]> grant all on test.* to root@'%'; #添加远程登录
MariaDB [mysql]> select host,user,password from user; #再次查看前三行信息
3、在sqlyong登录访问即可成功
4、*(选)修改登录密码
MariaDB [mysql]> set password for root@'%' = password('root'); #修改远程登录初始密码为root
Query OK, 0 rows affected (0.01 sec)
MariaDB [mysql]> select host,user,password from user; #查看修改后信息
MariaDB [mysql]> grant all on test.* to root@'%' identified by '000000' with grant option
# 第二次修改密码,改为000000