CentOS7使用yum源安装MariaDB10.5
1、编辑mariadb的yum源,内容从官方获取
https://mariadb.org/download/?t=repo-config&d=CentOS+7+%28x86_64%29&v=10.5&r_m=blendbyte
[root@server yum.repos.d]# vim mariadb.repo
# https://mariadb.org/download/
[mariadb]
name = MariaDB
baseurl = https://tw1.mirror.blendbyte.net/mariadb/yum/10.5/centos7-amd64
gpgkey=https://tw1.mirror.blendbyte.net/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
[root@server yum.repos.d]#
2、清理缓存
[root@server yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: base extras mariadb updates
Cleaning up list of fastest mirrors
Other repos take up 13 M of disk space (use --verbose for details)
[root@server yum.repos.d]#
3、更新缓存
[root@server yum.repos.d]# yum makecache
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
* base: mirror.lzu.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
mariadb | 3.4 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/14): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/14): extras/7/x86_64/filelists_db | 277 kB 00:00:00
(3/14): extras/7/x86_64/primary_db | 250 kB 00:00:00
(4/14): extras/7/x86_64/other_db | 149 kB 00:00:00
(5/14): base/7/x86_64/primary_db | 6.1 MB 00:00:01
(6/14): mariadb/updateinfo | 5.8 kB 00:00:00
(7/14): base/7/x86_64/other_db | 2.6 MB 00:00:01
(8/14): mariadb/primary_db | 74 kB 00:00:00
(9/14): mariadb/filelists_db | 375 kB 00:00:02
(10/14): mariadb/other_db | 8.6 kB 00:00:00
(11/14): base/7/x86_64/filelists_db | 7.2 MB 00:00:03
(12/14): updates/7/x86_64/other_db | 1.1 MB 00:00:01
(13/14): updates/7/x86_64/primary_db | 17 MB 00:00:02
(14/14): updates/7/x86_64/filelists_db | 9.4 MB 00:00:04
元数据缓存已建立
[root@server yum.repos.d]# yum repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.lzu.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
源标识 源名称 状态
base/7/x86_64 CentOS-7 - Base 10,072
extras/7/x86_64 CentOS-7 - Extras 516
mariadb MariaDB 100
updates/7/x86_64 CentOS-7 - Updates 4,156
repolist: 14,844
4、查看mariadb组件
[root@server yum.repos.d]# rpm -qa |grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
5、安装mariadb数据库服务器和客户端
[root@server yum.repos.d]# sudo yum install MariaDB-server MariaDB-client
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.lzu.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 MariaDB-client.x86_64.0.10.5.17-1.el7.centos 将被 安装
--> 正在处理依赖关系 MariaDB-common,它被软件包 MariaDB-client-10.5.17-1.el7.centos.x86_64 需要
---> 软件包 MariaDB-server.x86_64.0.10.5.17-1.el7.centos 将被 安装
--> 正在处理依赖关系 galera-4,它被软件包 MariaDB-server-10.5.17-1.el7.centos.x86_64 需要
--> 正在检查事务
---> 软件包 MariaDB-common.x86_64.0.10.5.17-1.el7.centos 将被 安装
--> 正在处理依赖关系 MariaDB-compat,它被软件包 MariaDB-common-10.5.17-1.el7.centos.x86_64 需要
---> 软件包 galera-4.x86_64.0.26.4.12-1.el7.centos 将被 安装
--> 正在处理依赖关系 socat,它被软件包 galera-4-26.4.12-1.el7.centos.x86_64 需要
--> 正在处理依赖关系 libboost_program_options-mt.so.1.53.0()(64bit),它被软件包 galera-4-26.4.12-1.el7.centos.x86_64 需要
--> 正在检查事务
---> 软件包 MariaDB-compat.x86_64.0.10.5.17-1.el7.centos 将被 舍弃
---> 软件包 boost-program-options.x86_64.0.1.53.0-28.el7 将被 安装
---> 软件包 mariadb-libs.x86_64.1.5.5.68-1.el7 将被 取代
---> 软件包 socat.x86_64.0.1.7.3.2-2.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
============================================================================================================================================================
Package 架构 版本 源 大小
============================================================================================================================================================
正在安装:
MariaDB-client x86_64 10.5.17-1.el7.centos mariadb 13 M
MariaDB-compat x86_64 10.5.17-1.el7.centos mariadb 2.2 M
替换 mariadb-libs.x86_64 1:5.5.68-1.el7
MariaDB-server x86_64 10.5.17-1.el7.centos mariadb 26 M
为依赖而安装:
MariaDB-common x86_64 10.5.17-1.el7.centos mariadb 81 k
boost-program-options x86_64 1.53.0-28.el7 base 156 k
galera-4 x86_64 26.4.12-1.el7.centos mariadb 9.9 M
socat x86_64 1.7.3.2-2.el7 base 290 k
事务概要
============================================================================================================================================================
安装 3 软件包 (+4 依赖软件包)
总下载量:52 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/mariadb/packages/MariaDB-common-10.5.17-1.el7.centos.x86_64.rpm: 头V4 DSA/SHA1 Signature, 密钥 ID 1bb943db: NOKEY--:--:-- ETA
MariaDB-common-10.5.17-1.el7.centos.x86_64.rpm 的公钥尚未安装
(1/7): MariaDB-common-10.5.17-1.el7.centos.x86_64.rpm | 81 kB 00:00:01
(2/7): MariaDB-compat-10.5.17-1.el7.centos.x86_64.rpm | 2.2 MB 00:00:01
(3/7): boost-program-options-1.53.0-28.el7.x86_64.rpm | 156 kB 00:00:00
(4/7): MariaDB-client-10.5.17-1.el7.centos.x86_64.rpm | 13 MB 00:00:05
(5/7): socat-1.7.3.2-2.el7.x86_64.rpm | 290 kB 00:00:00
(6/7): galera-4-26.4.12-1.el7.centos.x86_64.rpm | 9.9 MB 00:00:03
(7/7): MariaDB-server-10.5.17-1.el7.centos.x86_64.rpm | 26 MB 00:00:07
------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 5.2 MB/s | 52 MB 00:00:10
从 https://tw1.mirror.blendbyte.net/mariadb/yum/RPM-GPG-KEY-MariaDB 检索密钥
导入 GPG key 0x1BB943DB:
用户ID : "MariaDB Package Signing Key <package-signing-key@mariadb.org>"
指纹 : 1993 69e5 404b d5fc 7d2f e43b cbcb 082a 1bb9 43db
来自 : https://tw1.mirror.blendbyte.net/mariadb/yum/RPM-GPG-KEY-MariaDB
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : MariaDB-common-10.5.17-1.el7.centos.x86_64 1/8
正在安装 : MariaDB-compat-10.5.17-1.el7.centos.x86_64 2/8
正在安装 : MariaDB-client-10.5.17-1.el7.centos.x86_64 3/8
正在安装 : boost-program-options-1.53.0-28.el7.x86_64 4/8
正在安装 : socat-1.7.3.2-2.el7.x86_64 5/8
正在安装 : galera-4-26.4.12-1.el7.centos.x86_64 6/8
正在安装 : MariaDB-server-10.5.17-1.el7.centos.x86_64 7/8
Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo
See the MariaDB Knowledgebase at https://mariadb.com/kb
Please report any problems at https://mariadb.org/jira
The latest information about MariaDB is available at https://mariadb.org/.
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
正在删除 : 1:mariadb-libs-5.5.68-1.el7.x86_64 8/8
验证中 : socat-1.7.3.2-2.el7.x86_64 1/8
验证中 : galera-4-26.4.12-1.el7.centos.x86_64 2/8
验证中 : MariaDB-compat-10.5.17-1.el7.centos.x86_64 3/8
验证中 : boost-program-options-1.53.0-28.el7.x86_64 4/8
验证中 : MariaDB-client-10.5.17-1.el7.centos.x86_64 5/8
验证中 : MariaDB-common-10.5.17-1.el7.centos.x86_64 6/8
验证中 : MariaDB-server-10.5.17-1.el7.centos.x86_64 7/8
验证中 : 1:mariadb-libs-5.5.68-1.el7.x86_64 8/8
已安装:
MariaDB-client.x86_64 0:10.5.17-1.el7.centos MariaDB-compat.x86_64 0:10.5.17-1.el7.centos MariaDB-server.x86_64 0:10.5.17-1.el7.centos
作为依赖被安装:
MariaDB-common.x86_64 0:10.5.17-1.el7.centos boost-program-options.x86_64 0:1.53.0-28.el7 galera-4.x86_64 0:26.4.12-1.el7.centos
socat.x86_64 0:1.7.3.2-2.el7
替代:
mariadb-libs.x86_64 1:5.5.68-1.el7
完毕!
6、查询mariadb组件
[root@server yum.repos.d]# rpm -qa |grep mariadb
[root@server yum.repos.d]#
[root@server yum.repos.d]# rpm -qa |grep MariaDB
MariaDB-client-10.5.17-1.el7.centos.x86_64
MariaDB-common-10.5.17-1.el7.centos.x86_64
MariaDB-compat-10.5.17-1.el7.centos.x86_64
MariaDB-server-10.5.17-1.el7.centos.x86_64
[root@server yum.repos.d]#
7、启动mariadb服务,加入开机启动
[root@server my.cnf.d]# systemctl status mariadb
● mariadb.service - MariaDB 10.5.17 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: inactive (dead)
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
[root@server my.cnf.d]# systemctl is-enabled mariadb
disabled
[root@server my.cnf.d]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@server my.cnf.d]#
8、开启服务,以引导模式初始化数据局
[root@server my.cnf.d]# systemctl start mariadb
[root@server my.cnf.d]#
[root@server my.cnf.d]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] Y //切换至unix_socket认证
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] Y //修改数据库的root账户密码
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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? [Y/n] n //不要禁止root远程登录数据库
... skipping.
By default, MariaDB 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? [Y/n] Y //删除test数据库和访问权限
- 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? [Y/n] Y //重新加载权限表
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@server my.cnf.d]#
[root@server my.cnf.d]# ps -ef |grep mariadb
mysql 3231 1 0 23:33 ? 00:00:00 /usr/sbin/mariadbd
root 3311 2481 0 23:35 pts/1 00:00:00 grep --color=auto mariadb
[root@server my.cnf.d]# more server.cnf
[mysqld]
log_bin = mysql-bin
binlog_ignore_db = mysql
server_id = 1
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
[root@server my.cnf.d]# systemctl restart mariadb
[root@server my.cnf.d]# systemctl status mariadb
● mariadb.service - MariaDB 10.5.17 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since 一 2022-09-05 23:42:28 CST; 1s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 3695 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 3653 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
Process: 3651 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Main PID: 3678 (mariadbd)
Status: "Taking your SQL requests now..."
CGroup: /system.slice/mariadb.service
└─3678 /usr/sbin/mariadbd
9月 05 23:42:28 server mariadbd[3678]: 2022-09-05 23:42:28 0 [Note] InnoDB: 10.5.17 started; log sequence number 45154; transaction id 20
9月 05 23:42:28 server mariadbd[3678]: 2022-09-05 23:42:28 0 [Note] Plugin 'FEEDBACK' is disabled.
9月 05 23:42:28 server mariadbd[3678]: 2022-09-05 23:42:28 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
9月 05 23:42:28 server mariadbd[3678]: 2022-09-05 23:42:28 0 [Note] InnoDB: Buffer pool(s) load completed at 220905 23:42:28
9月 05 23:42:28 server mariadbd[3678]: 2022-09-05 23:42:28 0 [Note] Server socket created on IP: '::'.
9月 05 23:42:28 server mariadbd[3678]: 2022-09-05 23:42:28 0 [Note] Reading of all Master_info entries succeeded
9月 05 23:42:28 server mariadbd[3678]: 2022-09-05 23:42:28 0 [Note] Added new Master_info '' to hash table
9月 05 23:42:28 server mariadbd[3678]: 2022-09-05 23:42:28 0 [Note] /usr/sbin/mariadbd: ready for connections.
9月 05 23:42:28 server mariadbd[3678]: Version: '10.5.17-MariaDB-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server
9月 05 23:42:28 server systemd[1]: Started MariaDB 10.5.17 database server.
[root@server my.cnf.d]# ps -ef |grep mariadb
mysql 3678 1 0 23:42 ? 00:00:00 /usr/sbin/mariadbd
root 3706 2481 0 23:43 pts/1 00:00:00 grep --color=auto mariadb
[root@server my.cnf.d]#
9、登录数据库
[root@server mysql]# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.17-MariaDB-log 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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)
MariaDB [(none)]> select version();
+---------------------+
| version() |
+---------------------+
| 10.5.17-MariaDB-log |
+---------------------+
1 row in set (0.000 sec)
MariaDB [(none)]> select @@datadir;
+-----------------+
| @@datadir |
+-----------------+
| /var/lib/mysql/ |
+-----------------+
1 row in set (0.000 sec)
MariaDB [(none)]> select @@basedir;
+-----------+
| @@basedir |
+-----------+
| /usr/ |
+-----------+
1 row in set (0.000 sec)
MariaDB [(none)]>
本文来自博客园,作者:花之旭,转载请注明原文链接:https://www.cnblogs.com/huazhixu/p/16660139.html