MariaDB Centos7 下安装MariaDB

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
云数据库 RDS PostgreSQL,高可用系列 2核4GB
简介: MariaDB Centos7 下安装MariaDB

Centos7下安装MariaDB


1、下载安装文件

rpm包为例,对于标准服务器安装,至少需要下载clientshared,serve文件(安装时如果少了,会有错误提示的

 



2、防止冲突,检查是否已经安装了MySQL

rpm -qa 'mysql*'

 

如有必要,移除已安装数据库

 

3、安装

[root@localhost mnt]# rpm -ivh MariaDB-*

warning: MariaDB-10.0.19-centos7-x86_64-client.rpm: Header V4 DSA/SHA1 Signature, key ID 1bb943db: NOKEY

error: Failed dependencies:

   mariadb is obsoleted by MariaDB-client-10.0.19-1.el7.centos.x86_64

   mariadb-libs < 1:10.0.19-1.el7.centos conflicts with MariaDB-common-10.0.19-1.el7.centos.x86_64

   mariadb-libs is obsoleted by MariaDB-shared-10.0.19-1.el7.centos.x86_64

 

解决方法:

[root@localhost mnt]# rpm -iUvh MariaDB-*  #如已经存在相关软件则更新,无则安装

 

说明:安装前确保已安装了必备软件包,比如perl

 

4、为MariaDB root用户设置密码

1)启动mysql服务

[root@localhost mnt]# /usr/sbin/mysqld start

150529  0:26:41 [Note] /usr/sbin/mysqld (mysqld 10.0.19-MariaDB) starting as process 2987 ...

150529  0:26:41 [ERROR] Fatal error: Please consult the Knowledge Base to find out how to run mysqld as root!

150529  0:26:41 [ERROR] Aborting

150529  0:26:41 [Note] /usr/sbin/mysqld: Shutdown complete

 

错误原因:

mysql默认拒绝用户使用root账户启动,因为拥有文件权限的用户可能导致MySQL Server使用root帐户创建文件(比如,~root/.bashrc),但root用户可以通过在命令后面加上"--user=root"选项来强行启动mysqld

 

可以以普通用户运行mysqld,为了安全起见,可用特殊的普通用户mysql,来管理mysql数据库

 

解决方法一:

[root@localhost mnt]# /usr/sbin/mysqld --user=root

150529  0:37:26 [Note] /usr/sbin/mysqld (mysqld 10.0.19-MariaDB) starting as process 3035 ...

150529  0:37:26 [Note] InnoDB: Using mutexes to ref count buffer pool pages

150529  0:37:26 [Note] InnoDB: The InnoDB memory heap is disabled

150529  0:37:26 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

150529  0:37:26 [Note] InnoDB: Memory barrier is not used

150529  0:37:26 [Note] InnoDB: Compressed tables use zlib 1.2.7

150529  0:37:26 [Note] InnoDB: Using Linux native AIO

150529  0:37:26 [Note] InnoDB: Using CPU crc32 instructions

150529  0:37:26 [Note] InnoDB: Initializing buffer pool, size = 128.0M

150529  0:37:27 [Note] InnoDB: Completed initialization of buffer pool

150529  0:37:27 [Note] InnoDB: Highest supported file format is Barracuda.

150529  0:37:27 [Note] InnoDB: 128 rollback segment(s) are active.

150529  0:37:27 [Note] InnoDB: Waiting for purge to start

150529  0:37:27 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.23-72.1 started; log sequence number 1616717

150529  0:37:27 [Note] Plugin 'FEEDBACK' is disabled.

150529  0:37:27 [Note] Server socket created on IP: '::'.

150529  0:37:27 [Note] Event Scheduler: Loaded 0 events

150529  0:37:27 [Note] /usr/sbin/mysqld: ready for connections.

Version: '10.0.19-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server

 

 

解决方法二:

1)编辑/etc/my.cnf,添加如下内容(意为mysqld组中的mysql用户

[root@localhost mnt]# vim /etc/my.cnf

 

#

# This group is read both both by the client and the server

# use it for options that affect everything

#

[client-server]

 

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

[myslqd]

user=mysql

~                                              

注意:这里的mysql用户是不是手动创建的,貌似是安装时默认创建的

 

2)以mysql用户运行mysqld(比root用户更安全

[root@localhost ~]# /usr/sbin/mysqld --user=mysql

150531  0:10:22 [Note] /usr/sbin/mysqld (mysqld 10.0.19-MariaDB) starting as process 2990 ...

150531  0:10:22 [Note] InnoDB: Using mutexes to ref count buffer pool pages

150531  0:10:22 [Note] InnoDB: The InnoDB memory heap is disabled

150531  0:10:22 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

150531  0:10:22 [Note] InnoDB: Memory barrier is not used

150531  0:10:22 [Note] InnoDB: Compressed tables use zlib 1.2.7

150531  0:10:22 [Note] InnoDB: Using Linux native AIO

150531  0:10:22 [Note] InnoDB: Using CPU crc32 instructions

150531  0:10:22 [Note] InnoDB: Initializing buffer pool, size = 128.0M

150531  0:10:22 [Note] InnoDB: Completed initialization of buffer pool

150531  0:10:23 [Note] InnoDB: Highest supported file format is Barracuda.

150531  0:10:23 [Note] InnoDB: 128 rollback segment(s) are active.

150531  0:10:23 [Note] InnoDB: Waiting for purge to start

150531  0:10:23 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.23-72.1 started; log sequence number 1616943

150531  0:10:23 [Note] Plugin 'FEEDBACK' is disabled.

150531  0:10:24 [Note] Server socket created on IP: '::'.

150531  0:10:24 [Note] Event Scheduler: Loaded 0 events

150531  0:10:24 [ERROR] mysqld: File './multi-master.info' not found (Errcode: 13 "Permission denied")

150531  0:10:24 [ERROR] Creation of Master_info index file './multi-master.info' failed

150531  0:10:24 [ERROR] Failed to initialize multi master structures

150531  0:10:24 [ERROR] Aborting

 

150531  0:10:24 [Note] InnoDB: FTS optimize thread exiting.

150531  0:10:24 [Note] InnoDB: Starting shutdown...

150531  0:10:25 [Note] InnoDB: Shutdown completed; log sequence number 1616953

150531  0:10:25 [Note] /usr/sbin/mysqld: Shutdown complete

 

如上,出错了,咋解决?

分析错误原因:无权限在当前目录下创建multi-master.info

 

解决方法:

[root@localhost ~]# find / -name multi-master.info

/var/lib/mysql/multi-master.info

[root@localhost ~]# cd /var/lib/mysql

 

[root@localhost mysql]# ll

total 110636

-rw-rw----. 1 mysql mysql    16384 May 31 00:10 aria_log.00000001

-rw-rw----. 1 mysql mysql       52 May 31 00:10 aria_log_control

-rw-rw----. 1 mysql mysql 12582912 May 31 00:10 ibdata1

-rw-rw----. 1 mysql mysql 50331648 May 31 00:10 ib_logfile0

-rw-rw----. 1 mysql mysql 50331648 May 29 00:18 ib_logfile1

-rw-r-----. 1 mysql root     13342 May 30 23:55 localhost.localdomain.err

-rw-rw----. 1 root  root         0 May 29 00:37 multi-master.info

drwx--x--x. 2 mysql mysql     4096 May 29 00:18 mysql

srwxrwxrwx. 1 mysql mysql        0 May 31 00:10 mysql.sock

drwx------. 2 mysql mysql     4096 May 29 00:18 performance_schema

[root@localhost mysql]# chown mysql:mysql multi-master.info

[root@localhost mysql]# ll

total 110636

-rw-rw----. 1 mysql mysql    16384 May 31 00:10 aria_log.00000001

-rw-rw----. 1 mysql mysql       52 May 31 00:10 aria_log_control

-rw-rw----. 1 mysql mysql 12582912 May 31 00:10 ibdata1

-rw-rw----. 1 mysql mysql 50331648 May 31 00:10 ib_logfile0

-rw-rw----. 1 mysql mysql 50331648 May 29 00:18 ib_logfile1

-rw-r-----. 1 mysql root     13342 May 30 23:55 localhost.localdomain.err

-rw-rw----. 1 mysql mysql        0 May 29 00:37 multi-master.info

drwx--x--x. 2 mysql mysql     4096 May 29 00:18 mysql

srwxrwxrwx. 1 mysql mysql        0 May 31 00:10 mysql.sock

drwx------. 2 mysql mysql     4096 May 29 00:18 performance_schema

 

再次验证,成功了

[root@localhost mysql]# /usr/sbin/mysqld --user=mysql

150531  0:15:53 [Note] /usr/sbin/mysqld (mysqld 10.0.19-MariaDB) starting as process 3026 ...

150531  0:15:53 [Note] InnoDB: Using mutexes to ref count buffer pool pages

150531  0:15:53 [Note] InnoDB: The InnoDB memory heap is disabled

150531  0:15:53 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

150531  0:15:53 [Note] InnoDB: Memory barrier is not used

150531  0:15:53 [Note] InnoDB: Compressed tables use zlib 1.2.7

150531  0:15:53 [Note] InnoDB: Using Linux native AIO

150531  0:15:53 [Note] InnoDB: Using CPU crc32 instructions

150531  0:15:53 [Note] InnoDB: Initializing buffer pool, size = 128.0M

150531  0:15:53 [Note] InnoDB: Completed initialization of buffer pool

150531  0:15:53 [Note] InnoDB: Highest supported file format is Barracuda.

150531  0:15:53 [Note] InnoDB: 128 rollback segment(s) are active.

150531  0:15:53 [Note] InnoDB: Waiting for purge to start

150531  0:15:54 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.23-72.1 started; log sequence number 1616953

150531  0:15:54 [Note] Plugin 'FEEDBACK' is disabled.

150531  0:15:54 [Note] Server socket created on IP: '::'.

150531  0:15:54 [Note] Event Scheduler: Loaded 0 events

150531  0:15:54 [Note] /usr/sbin/mysqld: ready for connections.

Version: '10.0.19-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server

 

5、修改默认用户的密码

[root@localhost ~]# /usr/bin/mysqladmin -u root -h localhost.localdomain password 'test1234';

 

也可以# /usr/bin/mysqladmin -u root password 'new-password'

 

注意:mariadb user表中的root用户和linuxroot账户没什么关联

 

6、移除安装时创建的测试数据库和匿名用户(强烈推荐)

[root@localhost ~]# /usr/bin/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

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

 

Enter current password for root (enter for none):

OK, successfully used password, moving on...

 

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

 

You already have a root password set, so you can safely answer 'n'.

 

Change the root password? [Y/n] n

... skipping.

 

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

... 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

- 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@localhost ~]#

 

7、关闭数据库

[root@localhost ~]# mysql -u root -ptest1234

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 5

Server version: 10.0.19-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

 

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

 

MariaDB [(none)]> shutdown;

Query OK, 0 rows affected (0.01 sec)

 

MariaDB [(none)]>

 

开启服务的终端可见关闭结果如下

150530 23:45:01 [Note] /usr/sbin/mysqld: Normal shutdown

 

150530 23:45:01 [Note] Event Scheduler: Purging the queue. 0 events

150530 23:45:01 [Note] InnoDB: FTS optimize thread exiting.

150530 23:45:01 [Note] InnoDB: Starting shutdown...

150530 23:45:03 [Note] InnoDB: Shutdown completed; log sequence number 1616867

150530 23:45:03 [Note] /usr/sbin/mysqld: Shutdown complete

 

8、创建用户与授权

MariaDB [(none)]> create user 'testacc'@'182.168.1.103' identified by 'test1234';

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> grant all on *.* to 'testacc'@'%' identified by 'test1234';

Query OK, 0 rows affected (0.00 sec)

 

[root@localhost ~]# mysql --protocol=tcp -P 3306 -h192.168.1.103 -utestacc -ptest1234

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 10

Server version: 10.0.19-MariaDB MariaDB Server

 

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

 

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

 

MariaDB [(none)]>

MariaDB [(none)]> exit

Bye

 

9、客户端工具远程连接

 

如上图,Error No.2003错误Can’t connect to MySQL server on ‘192.168.1.103’

 



解决方法:

#禁止开机启动防火墙

[root@localhost ~]# systemctl disable firewalld.service

rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'

rm '/etc/systemd/system/basic.target.wants/firewalld.service'

 

#停止防火墙

[root@localhost ~]# systemctl stop firewalld.service

[root@localhost ~]# systemctl start firewalld.service

 



 

参考连接:

https://mariadb.com/kb/en/mariadb/installing-mariadb-with-the-rpm-tool/

 

 

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
3月前
|
存储 Ubuntu Linux
VMware-安装CentOS系统教程及安装包
虚拟机相当于是一个独立于你电脑的环境,在这个环境上面,你可以安装Linux、Windows、Ubuntu等各个类型各个版本的系统,在这个系统里面你不用担心有病读等,不用担心文件误删导致系统崩溃。 虚拟机也和正常的电脑系统是一样的,也可以开关机,不用的时候,你关机就可以了,也不会占用你的系统资源,使用起来还是比较方便 这里也有已经做好的CentOS 7系统,下载下来解压后直接用VMware打开就可以使用
743 69
|
2月前
|
存储 分布式计算 Linux
安装篇--CentOS 7 虚拟机安装
VMware 装 CentOS 7 不知道从哪下手?这篇超详细图文教程手把手教你在 VMware Workstation 中完成 CentOS 7 桌面系统的完整安装流程。从 ISO 镜像下载、虚拟机配置,到安装图形界面、设置用户密码,每一步都有截图讲解,适合零基础新手快速上手。装好之后无论你是要搭 Hadoop 集群,还是练 Linux ,这个环境都够你折腾一整天!
959 2
|
3月前
|
Ubuntu Linux 索引
Centos 7、Debian及Ubuntu系统中安装和验证tree命令的指南。
通过上述步骤,我们可以在CentOS 7、Debian和Ubuntu系统中安装并验证 `tree`命令。在命令行界面中执行安装命令,然后通过版本检查确认安装成功。这保证了在多个平台上 `tree`命令的一致性和可用性,使得用户无论在哪种Linux发行版上都能使用此工具浏览目录结构。
351 78
|
2月前
|
Ubuntu 安全 关系型数据库
安装MariaDB服务器流程介绍在Ubuntu 22.04系统上
至此, 您已经在 Ubuntu 22.04 系统上成功地完成了 MariadB 的标准部署流程,并且对其进行基础但重要地初步配置加固工作。通过以上简洁明快且实用性强大地操作流程, 您现在拥有一个待定制与使用地强大 SQL 数据库管理系统。
207 18
|
2月前
|
安全 关系型数据库 MySQL
CentOS 7 yum 安装 MySQL教程
在CentOS 7上安装MySQL 8,其实流程很清晰。首先通过官方Yum仓库来安装服务,然后启动并设为开机自启。最重要的环节是首次安全设置:需要先从日志里找到临时密码来登录,再修改成你自己的密码,并为远程连接创建用户和授权。最后,也别忘了在服务器防火墙上放行3306端口,这样远程才能连上。
499 16
|
4月前
|
Linux 网络安全 Apache
针对在Centos/Linux安装Apache过程中出现的常见问题集锦
以上每个问题的解决方案应深入分析错误日志、系统消息和各种配置文件,以找到根本原因并加以解决。务必保持系统和Apache软件包更新到最新版本,以修复已知的bugs和安全漏洞。安装和管理Web服务器是一项需要细致关注和不断学习的任务。随着技术的发展,推荐定期查看官方文档和社区论坛,以保持知识的更新。
230 80
|
2月前
|
Ubuntu 安全 关系型数据库
安装MariaDB服务器流程介绍在Ubuntu 22.04系统上
至此, 您已经在 Ubuntu 22.04 系统上成功地完成了 MariadB 的标准部署流程,并且对其进行基础但重要地初步配置加固工作。通过以上简洁明快且实用性强大地操作流程, 您现在拥有一个待定制与使用地强大 SQL 数据库管理系统。
222 15
|
3月前
|
存储 关系型数据库 MySQL
在CentOS 8.x上安装Percona Xtrabackup工具备份MySQL数据步骤。
以上就是在CentOS8.x上通过Perconaxtabbackup工具对Mysql进行高效率、高可靠性、无锁定影响地实现在线快速全量及增加式数据库资料保存与恢复流程。通过以上流程可以有效地将Mysql相关资料按需求完成定期或不定期地保存与灾难恢复需求。
309 10
|
3月前
|
运维 网络协议 Linux
CentOS下Bind服务的安装与故障排查
通过以上的步骤,您应该能够在CentOS系统上安装并配置BIND DNS服务,并进行基本的故障排查。
330 0
|
3月前
|
存储 Ubuntu Linux
安卓手机免root安装各种Linux系统:Ubuntu, Centos,Kali等
此外还可以安装Slackware、Archstrike等系统,还可以通过github查找方法安装更多有趣的东西。 昨日小编就是通过Termux安装的Kali Linux工具包。