centos6安装mariadb10全过程

前端之家收集整理的这篇文章主要介绍了centos6安装mariadb10全过程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

问题

centos直接安装mariadb会遇到众多问题。如果直接安装MysqL,由于oracle官方维护不够给力,使用起来有一定的风险,所以必须要安装mariadb。如果用yum安装(在阿里云亲测),由于网络不好,下载安装包的过程中,总是容易中断。如果用源码安装,先要求装gnutls,gnutls又依赖nettle,但是nettle即使版本是按gnutls要求安装的,仍然会报:Libnettle 3.1 was not found. 的问题



规划:
日志路径:/home/datum/data/logs/mariadb
数据库表数据路径: /home/datum/data/appdata/maria_data/dbdata
sock路径: /home/datum/data/appdata/maria_data/sock/
给相关的所有文件夹递归的赋权限:chmod -R 777/home/datum/data



下载安装文件
先进入 https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.2.6/yum/centos6-amd64/rpms/ 选择要安装的具体文件
再用命令下载安装文件
wget https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.2.6/yum/centos6-amd64/rpms/MariaDB-10.2.6-centos6-x86_64-client.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.2.6/yum/centos6-amd64/rpms/MariaDB-10.2.6-centos6-x86_64-server.rpm

如果下载失败,进入官方库下载: http://yum.mariadb.org/10.2/centos6-amd64/rpms/

wgethttp://yum.mariadb.org/10.2/centos6-amd64/rpms/MariaDB-10.2.9-centos6-x86_64-common.rpm

wget http://yum.mariadb.org/10.2/centos6-amd64/rpms/MariaDB-10.2.9-centos6-x86_64-compat.rpm

wget http://yum.mariadb.org/10.2/centos6-amd64/rpms/MariaDB-10.2.9-centos6-x86_64-client.rpm

wgethttp://yum.mariadb.org/10.2/centos6-amd64/rpms/MariaDB-10.2.9-centos6-x86_64-server.rpm





安装:

卸载老版,以免产生冲突:卸载老版,以免产生冲突 : yum remove MysqL-libs

安装所依赖的基础库:yum -y install galera perl perl-DBI

安装commn,compat,命令:rpm -ivh MariaDB-10.2.9-centos6-x86_64-common.rpm MariaDB-10.2.9-centos6-x86_64-compat.rpm

安装客户端:rpm -ivh MariaDB-10.2.9-centos6-x86_64-client.rpm

再安装server,命令: rpm -ivh MariaDB-10.2.6-centos6-x86_64-server.rpm

注意commn,compat要一起安装,否则会报以下的错误

#rpm -ivh MariaDB-10.2.9-centos6-x86_64-compat.rpm
warning: MariaDB-10.2.9-centos6-x86_64-compat.rpm: Header V4 DSA/SHA1 Signature,key ID 1bb943db: NOKEY
error: Failed dependencies:
MariaDB-common is needed by MariaDB-compat-10.2.9-1.el6.x86_64
# rpm -ivh MariaDB-10.2.9-centos6-x86_64-common.rpm
warning: MariaDB-10.2.9-centos6-x86_64-common.rpm: Header V4 DSA/SHA1 Signature,key ID 1bb943db: NOKEY
error: Failed dependencies:
MariaDB-compat is needed by MariaDB-common-10.2.9-1.el6.x86_64



数据库配置:

配置数据库。先看有没有文件/etc/my.cnf ,如果没有,执行cp /usr/share/MysqL/my-large.cnf /etc/my.cnf

先将配置文件拷到默认位置,然后再修改里面的内容



配置内容

# The following options will be passed to all MariaDB clients
[client]
#password = your_password
port = 3306
socket=/home/datum/data/appdata/maria_data/sock/MysqL.sock


# Here follows entries for some specific programs


# The MariaDB server
[MysqLd]
port = 3306
datadir=/home/datum/data/appdata/maria_data/dbdata
socket=/home/datum/data/appdata/maria_data/sock/MysqL.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of cpu's*2 for thread_concurrency
thread_concurrency = 8


# Replication Master Server (default)
# binary logging is required for replication
log-bin=MysqL-bin


# binary logging format - mixed recommended
binlog_format=mixed


# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1


log-error=/home/datum/data/logs/mariadb/MysqL.log
slow-query-log = 1
slow-query-log-file =/home/datum/data/logs/mariadb/MysqL-slow.log
long_query_time =5




wait_timeout=90000
interactive_timeout=90000


#10s per transaction
innodb_lock_wait_timeout=10


#MysqL 事件计划开启
event_scheduler=1


#与cpu相关=cpu*2
thread_concurrency=20


# from net http://www.tuicool.com/articles/a6jeiu http://www.jb51.net/article/58537.htm
# 启用 InnoDB 的每张表一个数据文件设置
innodb_file_per_table=1
# 配置 MysqL 的线程缓存数量
thread_cache_size =32
# 配置 MysqL查询缓存容量。验证: show status like '%Qcache%';
query_cache_type=1
# query_cache_limit = 256K
# query_cache_min_res_unit = 2k
query_cache_size=128M




[MysqLdump]
quick
max_allowed_packet = 16M


[MysqL]
no-auto-rehash
# Remove the next comment character if you are not familiar with sql
#safe-updates


[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M


[MysqLhotcopy]
interactive-timeout


设置相关文件夹的权限: chown -R MysqL:MysqL /home/datum/data/logs/mariadb

chown -R MysqL:MysqL /home/datum/data/appdata/maria_data

chmod -R 777 /home/datum/data/appdata/maria_data

chmod -R 777 /home/datum/data/logs/mariadb


执行mariadb初始化命令:

cd /etc/my.cnf.d/

MysqL_install_db --defaults-file=/etc/my.cnf --datadir=/home/datum/data/appdata/maria_data/dbdata/ --user=MysqL



启动mariadb(MysqL): service MysqL start



mariadb重置密码命令:MysqLadmin -u root password "123456"

允许远程登录: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION; flush privileges;
其中,123456为root的密码。root密码设置完后,必须要重启MysqL才能生效


重启mariadb(MysqL): service MysqL restart



mariadb用户名密码登录命令: MysqL -uroot -p123456
允许远程登录: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION; flush privileges;
其中,123456为root的密码

查看数据库: show databases;
切换数据库: use MysqL;
展示所有表: show tables;
卸载老版,以免产生冲突
原文链接:https://www.f2er.com/centos/376918.html

猜你在找的CentOS相关文章