Centos7 使用yum安装MariaDB与MariaDB的简单配置与使用
一.mariadb的安装
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。
开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。
MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。
方法1:阿里源下yum安装mariadb版本会旧一点
Red Hat Enterprise Linux/CentOS 7.0 发行版已将默认的数据库从 MySQL 切换到MariaDB。
安装命令 # yum -y install mariadb mariadb-server 安装完成MariaDB,首先启动MariaDB,两条命令都可以 systemctl start mariadb #centos6命令 service mariadb start
方法2:yum安装mariadbrepo仓库配置安装
# 如果已经添加了阿里云的源又想安装最新版本的mariadb,那么少就使用以下步骤
# 编辑创建mariadb.repo仓库文件 vi /etc/yum.repos.d/MariaDB.repo 添加repo仓库配置 [mariadb] name=MariaDB baseurl=http://yum.mariadb.org/10.1/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
当 MariaDB 仓库地址添加好后,你可以通过下面的一行命令轻松安装 MariaDB。
yum install MariaDB-server MariaDB-client -y
二.MariaDB基本配置
1.开启关闭与查看mariadb命令
mariadb数据库的相关命令是:
systemctl start mariadb #启动MariaDB
systemctl stop mariadb #停止MariaDB
systemctl restart mariadb #重启MariaDB
systemctl enable mariadb #设置开机启动
# 查看mariadb进程
[root@node home]# netstat -ntlp |grep tcp 0.0.0.0: 0.0.0.0:* LISTEN /mysqld
2.初始化MariaDB 数据库
在确认 MariaDB 数据库软件程序安装完毕并成功启动后请不要立即使用。为了确保数据 库的安全性和正常运转,需要先对数据库程序进行初始化操作。这个初始化操作涉及下面 5 个 步骤。
设置 root 管理员在数据库中的密码值(注意,该密码并非 root 管理员在系统中的密 码,这里的密码值默认应该为空,可直接按回车键)。
设置 root 管理员在数据库中的专有密码。
随后删除匿名账户,并使用 root 管理员从远程登录数据库,以确保数据库上运行的业
务的安全性。
删除默认的测试数据库,取消测试数据库的一系列访问权限。
刷新授权列表,让初始化的设定立即生效。
初始化命令: mysql_secure_installation 首先是设置密码,会提示先输入密码 Enter current password for root (enter for none):<–初次运行直接回车 设置密码 Set root password? [Y/n] y<– 是否设置root用户密码,输入y并回车或直接回车 New password: <– 设置root用户的密码 Re-enter new password: <– 再输入一次你设置的密码 其他配置 Remove anonymous users? [Y/n] y<– 是否删除匿名用户,回车 Disallow root login remotely? [Y/n] n<–是否禁止root远程登录,回车,不过一般为y Remove test database and access to it? [Y/n] y<– 是否删除test数据库,回车 Reload privilege tables now? [Y/n] y<– 是否重新加载权限表,回车 初始化MariaDB完成,接下来测试登录 # mysql -uroot -p 进入数据库(数据库中的操作命令和mysql是一样的)
3.中文编码设置,utf8编码
文件/etc/my.cnf vi /etc/my.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 进行查看就支持utf8了
三.mariadb的使用
关于mariadb的使用其实是和mysql的语句完全是一样的
1.开启关闭和设置开机启动
mariadb数据库的相关命令是:
systemctl start mariadb #启动MariaDB systemctl stop mariadb #停止MariaDB systemctl restart mariadb #重启MariaDB systemctl enable mariadb #设置开机启动
2.设置密码建库建表
# 修改mysql密码
MariaDB [(none)]> set password = PASSWORD('hsz123');
Query OK, rows affected (0.34 sec)
# 创建tests数据库 如果加charset=utf8 表示指定utf8编码
MariaDB [(none)]> create database test;
Query OK, row affected (0.00 sec)
# 进入test数据库
MariaDB [(none)]> use test;
Database changed
# 创建mytest数据表
MariaDB [test]> create table mytest(id int,name char());
Query OK, rows affected (0.02 sec)
# 查看数据表
MariaDB [test]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| mytest |
+----------------+
row in set (0.00 sec)
# 查看mytest数据表的表结构
MariaDB [test]> desc mytest;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int() | YES | | NULL | |
| name | char() | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
rows in set (0.05 sec)
2.简单的增删改查
# 给表增加两条数据 MariaDB [test]> insert into mytest(id,name) values(,"zero"),(,"one"); Query OK, rows affected (0.35 sec) Records: Duplicates: Warnings: # 查看id,name 字段mytest的数据 MariaDB [test]> select id,name from mytest; +------+------+ | id | name | +------+------+ | | zero | | | one | +------+------+ rows in set (0.00 sec) # 删除mytest表中id= 的数据 MariaDB [test]> delete from mytest id=; ERROR (): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'id=2' at line MariaDB [test]> delete from mytest where id=; Query OK, row affected (0.00 sec) # 查看表的所有数据 MariaDB [test]> select * from mytest; +------+------+ | id | name | +------+------+ | | zero | +------+------+ row in set (0.01 sec) # 更新表id=1表的字段name=ten MariaDB [test]> update mytest set name=ten where id=; ERROR (42S22): Unknown column 'ten' in 'field list' MariaDB [test]> update mytest set name="ten" where id=; Query OK, row affected (0.00 sec) Rows matched: Changed: Warnings: MariaDB [test]> select * from mytest; +------+------+ | id | name | +------+------+ | | ten | +------+------+ row in set (0.01 sec)
3.关于用户及权限常用命令
# 创建用户和密码 MariaDB [test]> create user zero@'%' identified by 'zero'; Query OK, rows affected (0.01 sec) mysql使用grant命令对账户进行授权,grant命令常见格式如下 grant 权限 on 数据库.表名 to 账户@主机名 对特定数据库中的特定表授权 grant 权限 on 数据库.* to 账户@主机名 对特定数据库中的所有表给与授权 grant 权限1,权限2,权限3 on *.* to 账户@主机名 对所有库中的所有表给与多个授权 grant all privileges on *.* to 账户@主机名 对所有库和所有表授权所有权限 #授予用户最大的权限,所有的权限 grant all privileges on *.* to username@'%' identified by 'password';
#授予zero用户,只有创建test数据库的权限 MariaDB [test]> grant create on test.* to zero@'%' identified by 'zero'; Query OK, rows affected (0.00 sec) # 所以查询zero用户的数据库只有如下所示 [root@node ~]# mysql -uzero -pzero Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , 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 | | test | +--------------------+ rows in set (0.00 sec) MariaDB [(none)]>
#授予one创建的权限,对于所有的库表生效 MariaDB [test]> grant create on *.* to one@"%" identified by 'one'; Query OK, rows affected (0.00 sec) # 所以查询数据库可以显示如下所示 [root@node ~]# mysql -uone -pone Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , 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 | | test | | text | +--------------------+ rows in set (0.00 sec) MariaDB [(none)]> # 删除one用户 MariaDB [test]> drop user one; Query OK, rows affected (0.00 sec) # 刷新权限 MariaDB [test]> flush privileges; Query OK, rows affected (0.00 sec)
4.数据库备份与恢复
# mysqldump命令用于备份数据库数据 ##备份所有数据库命令 [root@node ~]# mysqldump -u root -p --all-databases > /tmp/db.dump Enter password: [root@node ~]# ll /tmp/db.dump -rw-r--r--. root root Sep : /tmp/db.dump ##备份单个数据库命令 [root@node ~]# mysqldump -u root -p text > /tmp/text.sql Enter password: [root@node ~]# ll /tmp/text.sql -rw-r--r--. root root Sep : /tmp/text.sql ## 将备份的数据库导入 [root@node ~]# mysql -uroot -p text2< /tmp/text.sql # 删除数据库 MariaDB [text2]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | text | | text2 | +--------------------+ rows in set (0.00 sec) MariaDB [text2]> drop database text; Query OK, rows affected (0.00 sec) MariaDB [text2]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | text2 | +--------------------+ rows in set (0.00 sec)
Centos7 使用yum安装MariaDB与MariaDB的简单配置与使用的更多相关文章
- 阿里云Centos7使用yum安装MySQL5.6的正确姿势
阿里云Centos7使用yum安装MySQL5.6 阿里云Centos7使用yum安装MySQL5.6 前言:由于某些不可抗力,我要在自己的阿里云服务器上搭建hadoop+hive+mysql+tom ...
- centos7通过yum安装nginx
centos7通过yum安装nginx nginx不支持centos7通过yum直接安装~~~ 1.查看操作系统位数[root@-jenkins ~]# rpm -aq|grep centos-rel ...
- <亲测>centos7通过yum安装JDK1.8(实际上是openjdk)
centos7通过yum安装JDK1.8 安装之前先检查一下系统有没有自带open-jdk 命令: rpm -qa |grep java rpm -qa |grep jdk rpm -qa |gr ...
- centos7.0 yum 安装php服务器
https://blog.csdn.net/jiaoshenmo/article/details/50923900 首先收一下:centos7.0用yum直接安装apache.php他们的默认版本是a ...
- CentOS7使用yum安装LNMP环境以后无法打开php页面
CentOS7使用yum安装LNMP环境以后无法打开php页面 页面提示为File not found 查看nginx错误日志/var/log/nginx/error.log提示如下 原因分析 ngi ...
- CentOS7通过 yum安装路径查询方法
CentOS7通过 yum安装路径查询方法 rpm -qa 然后执行 rpm -ql 软件名称 就可以显示软件的安装路径. 原文博客的链接地址:https://cnblogs.com/qzf/
- centos7 下 yum 安装Nginx
centos7 下 yum 安装和配置 Nginx 添加yum源 Nginx不在默认的yum源中,可以使用epel或者官网的yum源,这里使用官网的yum源 rpm -ivh http://nginx ...
- Centos7通过yum安装jdk8
1.Centos7通过yum安装jdk8 2.Centos7通过yum安装jdk8
- CentOS7 通过YUM安装MySQL5.7 linux
CentOS7 通过YUM安装MySQL5.7 1.进入到要存放安装包的位置 cd /home/lnmp 2.查看系统中是否已安装 MySQL 服务,以下提供两种方式: rpm -qa | grep ...
- CentOS7用yum安装wget命令后仍然提示命令找不到的解决方法
需求:用的AWS实例自带的CentOS7用yum安装wget命令后扔提示命令找不到,后面用源码安装方式解决,下面先讲解决方法,疑问及知识点扩展最后写出 1.问题(因是mini版本系统,有些基本命令扔需 ...
随机推荐
- JAVA(3)之关于运算符的优先级
关于运算符的优先级,我做了一个小测试,区别在于平常的运算思维和计算机思维 int result=2; result =(result=result*2)*6*(result=3+result); Sy ...
- java篇 之 静态
Final:不可改变 Static:静态修饰符,在编译阶段就能确定了,可以修饰成员变量,相应的称之为静态变量 是一个共享的变量(被这个类和这个类所产生的对象所共享的,他是唯一的,出生时间 为类第一次产 ...
- wampserver3.0.6 外网 不能访问
# 开始 今天在服务器上安装了wampserver3.0.6 然后在我的电脑浏览器上面打开服务器ip提示 Forbidden 下面一行小字提示没有权限访问"/"目录 # 解决 打开 ...
- github提交代码
下载git for windows,安装 第一步: 第二步: 第三步:不存在repository,点击 create a repository 第四步:切换至History菜单下,并点击publish ...
- Laravel Vuejs 实战:开发知乎 (8)美化编辑器
1.使用UEditor增量包: simple-ueditors 执行下载: git clone https://github.com/JellyBool/simple-ueditor.git 2.用此 ...
- java 面试题 mybatis 篇
1. 一级缓存和二级缓存? 一级缓存策略: 二级缓存策略: 2. 缓存回收策略 LRU – 最近最少使用的:移除最长时间不被使用的对象. FIFO – 先进先出:按对象进入缓存的顺序来移除它们. ...
- 洛谷 P1843 奶牛晒衣服(二分答案)
嗯... 题目链接:https://www.luogu.com.cn/problem/P1843 我们二分枚举时间,看看那些衣服在蒸发后还要用烘干机,则用cnt记录它的时间. 注意w数组在操作中不能变 ...
- 《MySQL命令执行过程和存储引擎概述》阅读笔记
使用MySQL的完整过程: 启动MySQL服务器程序. 启动MySQL客户端程序并连接到服务器程序. 在客户端程序中输入一些命令语句发送到服务器程序,服务器程序收到这些请求后,会根据请求的内容来操作具 ...
- 02-Docker认识与原理
目录 02-Docker认识与原理 参考 Docker认识 Docker特性 Docker对比VM Docker社区版本 Docker原理 Docker engine Docker architect ...
- 实现一个简易的Unity网络同步引擎——netgo
实现一个简易的Unity网络同步引擎Netgo 目前GOLANG有大行其道的趋势,尤其是在网络编程方面.因为和c/c++比较起来,虽然GC占用了一部分机器性能,但是出错概率小了,开发效率大大提升,而且 ...