Centos 6.8 安装MariaDB 10 ,在线安装

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

一、检查系统是否安装其他版本Mysql数据库

yum list installed | grep mysql
yum -y remove mysql-libs.x86_64

二、安装配置

源的选择:通过Maria官方提供的安装方式,源是国外的源,下载非常慢,会导致下载失败!所以这里我们选择国内的源。

1.在线源生成器生成源
1.1通过MariaDB提供的在线源生成器生成源,不过很慢,会下载失败
在这里插入图片描述
1.2通过国内源生成器生成源,推荐这种方式
在这里插入图片描述
2.新建文件" vi /etc/yum.repos.d/MariaDB.repo “,并将源内容拷贝到文件里,然后ESC退出,” :wq "保存。

[root@holer ~]# vi /etc/yum.repos.d/MariaDB.repo

# 在线生成器生成的源内容,使用国内源
# MariaDB 10.0 CentOS repository list - created 2019-09-19 01:05 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://mirrors.ustc.edu.cn/mariadb/yum/10.0/centos6-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

3.安装MaiaDB

yum repolist all | grep mysql
yum -y install MariaDB-server MariaDB-client

三、设置远程root

启动mysql服务

service mysql start

执行" mysql_secure_installation ",设置内容如下:

  1. 为root用户设置密码
  2. 删除匿名账号
  3. 取消root用户远程登录
  4. 删除test库和对test库的访问权限
  5. 刷新授权表使修改生效
[root@holer ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, 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 MySQL
root user without the proper authorisation.

Set root password? [Y/n] y						##<– 是否设置root用户密码,输入y并回车或直接回车
New password: 									##<– 设置root用户的密码
Re-enter new password: 							##<– 再输入一次你设置的密码
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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, MySQL 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] n			##<– 是否删除test数据库,直接回车
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 							##<– 是否重新加载权限表,直接回车
 ... Success!

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up...

登录root用户建立远程连接

[root@holer ~]# mysql -uroot -p

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你设置的密码' WITH GRANT OPTION;
MariaDB [(none)]> flush privileges;

四、设置UTF-8编码

1.登录root用户,查看MariaDB原本编码

[root@holer ~]# mysql -uroot -p

MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";

2.编辑MariaDB的" vi /etc/my.cnf.d/server.cnf “文件,设置编码,然后ESC退出,” :wq "保存。

[root@holer ~]# vi /etc/my.cnf.d/server.cnf

[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

3.编辑MariaDB的" vi /etc/my.cnf.d/mysql-clients.cnf "文件,设置编码。

[root@holer ~]# vi /etc/my.cnf.d/mysql-clients.cnf

[mysql]
default-character-set=utf8

4.重启MariaDB服务,查看验证编码

[root@holer ~]# service mysql restart
[root@holer ~]# mysql -uroot -p

MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";

五、对外开放远程

首先,编辑" vi /etc/sysconfig/iptables “文件
在这里插入图片描述
然后按” i “键,插入防火墙策略,按ESC退出后” :wq "保存

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

在这里插入图片描述
最后重启" service iptables restart "
在这里插入图片描述

六、设置开机启动

2、3、4都是on代表开机自动启动

chkconfig --list | grep mysql
chkconfig mysql on

七、启动关闭

启动:# service mysql start
关闭:# service mysql stop
重启:# service mysql restart

查看版本:mysql -V
mysql  Ver 15.1 Distrib 10.0.38-MariaDB, for Linux (x86_64) using readline 5.1

查看进程:ps -ef | grep mysql
如果有mysqld_safe和mysqld两个进程,说明MySQL服务当前在启动状态;

在这里插入图片描述

八、参考网址

https://www.cnblogs.com/jeacy/p/7183508.html
https://www.cnblogs.com/kevingrace/p/8556239.html
https://www.cnblogs.com/pasoraku/p/4455983.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值