Centos7 下安装MariaDB

by:授客 QQ1033553122

1、下载安装文件

rpm包为例,对于标准服务器安装,至少需要下载client,shared,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用户和linux的root账户没什么关联

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/

MariaDB Centos7 下安装MariaDB的更多相关文章

  1. CentOS7下安装MariaDB

    环境:Window10 上建立 VMWare 虚拟机,EasyInstaller 方式安装 CentOS 7 1. “失败”的经历 备份原 repo 文件,并更改 yum 源(方法详见修改yum源)为 ...

  2. CentOS7下安装Mariadb 10.3.17

    1. install lsb packagesudo yum install -y redhat-lsb 2.install net-tools packagesudo yum install -y ...

  3. Linux - centos7 下 MySQL(mariadb) 和 主从复制

    目录 Linux - centos7 下 MySQL(mariadb) 和 主从复制 MySQL(mariadb) 安装MySQL(mariadb) 配置数据库的中文支持 在远程用 mysql客户端去 ...

  4. CentOS7下安装MySQL并配置远程连接

    一.CentOS7下安装MySQL数据库 CentOS7默认的安装包里面已经没有 MySQL-Server安装包了,远程镜像中也没有了. 默认的是MariaDB (MySQL的一个分支,开发这个分支的 ...

  5. Centos7 下安装mysql数据库

    centos7系统,安装mysql发现已经默认的是mariadb. 只能安装mariadb,mariadb是mysql一个分支,对mysql完全支持 1 安装 yum -y install maria ...

  6. CentOS7 下 安装 supervisor以及使用

    CentOS7 下 安装 supervisor 以及使用 手动安装 [注] linux环境必须安装 python 1.获取supervisor包:[https://pypi.python.org/py ...

  7. Linux CentOs7 下安装 redis

    Linux CentOs7 下安装 redis 请将以下命令放入linux命令行中运行 如果安装过程前没有安装GCC请先安装  命令如下 $ yum install gcc-c++ $ wget ht ...

  8. Centos7下安装配置Redsocks

    Redsocks是一个开源的网络程序,代码依赖开源的libevent网络库.Redsocks允许你将所有TCP连接重定向到SOCKS或HTTPS代理,比如Shadowsocks(Centos7下安装配 ...

  9. CentOS7下安装SVN服务端

    CentOS7下安装SVN服务 1. yum命令即可方便的完成安装# sudo yum install subversion 测试安装是否成功:# svnserve --version 更改svn的默 ...

随机推荐

  1. android电量优化 总结

    移动设备电池容量小,耗电较快(基本一天一充) ,故我们在应用开发使用相关组件和方法时候必须考虑耗电情况: 一   通过Battery Historian查看手机的耗电状况, 可以知道Android的在 ...

  2. java多线程并发控制countDownLatch和cyclicBarrier的使用

    java主线程等待所有子线程执行完毕在执行,这个需求其实我们在工作中经常会用到,比如用户下单一个产品,后台会做一系列的处理,为了提高效率,每个处理都可以用一个线程来执行,所有处理完成了之后才会返回给用 ...

  3. Fragment中启动一个新的Activity

    最近遇到一个小问题,就是我在主界面中用的是Fragment,其中四个Fragment,然后打算在其中一个里边,写一个TextView(准确地说是Linearout)的单击事件,然后跳转到另外一个Act ...

  4. Javac中对import关键字进行的处理

    参考文章: (1)关于类的符号输入过程第二篇 ImportScope中存储的为ImportEntry,继承了Scope.Entry类并且多定义了个origin属性,也就是符号的最终来源.除此之外还对g ...

  5. Kafka 副本失效

    Kafka源码注释中说明了一般有两种情况会导致副本失效: follower副本进程卡住,在一段时间内根本没有想leader副本发起同步请求,比如频繁的Full GC. follower副本进程同步过慢 ...

  6. hibernate 验证异常 javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint

    使用hibernate validator出现上面的错误, 需要 注意 @NotNull 和 @NotEmpty  和@NotBlank 区别 @NotEmpty 用在集合类上面@NotBlank 用 ...

  7. C# 1.0 到 4.0 的进化 1

    定义一个产品类 Product C# 1 using System; using System.Collections; namespace C1 { public class Product { s ...

  8. 用new关键字对一个String 变量赋值和用literal值直接赋值有什么不同(转)

    String str1="ABC": 和String str2 = new String("ABC"); 有什么区别. String str1="AB ...

  9. Java设计模式学习记录-单例模式

    前言 已经介绍和学习了两个创建型模式了,今天来学习一下另一个非常常见的创建型模式,单例模式. 单例模式也被称为单件模式(或单体模式),主要作用是控制某个类型的实例数量是一个,而且只有一个. 单例模式 ...

  10. Winform下判断文件和文件夹是否存在

    //选择文件夹 FolderBrowserDialog dia = new FolderBrowserDialog(); if (dia.ShowDialog() == System.Windows. ...