CentOS安装并设置MariaDB

2024-05-15 01:32:47

说明: 首先必须能链接外网. 如果不能直接访问,那也可以设置代理,请参考: 在内网机器上设置yum代理

使用 yum 的权限要求是 root 用户,如果你不是,那么可以需要 在 shell命令之前加上 sudo, 或者 su root  切换到 super 管理员进行操作. 并可能需要输入密码.

1. 添加 yum 数据源;

建议命名为 MariaDB.repo 类似的名字:

[plain] view plain copy 在CODE上查看代码片派生到我的代码片

cd /etc/yum.repos.d/

vim /etc/yum.repos.d/MariaDB.repo

然后,写入文件内容:(建议使用 10.0)

[plain] view plain copy 在CODE上查看代码片派生到我的代码片

# MariaDB 10.0 CentOS repository list - created 2015-08-12 10:59 UTC

# http://mariadb.org/mariadb/repositories/

[mariadb]

name = MariaDB

baseurl = http://yum.mariadb.org/10.0/centos6-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

该文件的内容是参考官网,并从官网上生成的,设置安装源仓库的 具体的地址为:  https://downloads.mariadb.org/mariadb/repositories/

选择好操作系统版本之后既可以查看,其他操作系统的安装源也可以在此处查看并设置。

如果服务器不支持https协议,或者gpgkey 保错,确保没问题的话,可以将 gpgcheck=1 修改为 gpgcheck=0,则不进行校验.

我的示例:

[root@localhost ~]# cat /etc/yum.repos.d/MariaDB.repo

# MariaDB 10.1 CentOS repository list - created 2017-04-05 08:04 UTC

# http://downloads.mariadb.org/mariadb/repositories/

[mariadb]

name = MariaDB

baseurl = http://yum.mariadb.org/10.1/centos6-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

2. 安装数据库

# yum remove MariaDB-server MariaDB-client

yum -y install MariaDB-server MariaDB-client

如果要删除旧的数据库可以使用remove, 参数 -y 是确认,不用提示。此处,安装的是服务器和客户端,一般来说安装这两个就可以了。

3. 启动数据库

如果不用进行其他的操作,则现在就可以直接启动数据库,并进行测试了。

# 查看mysql状态;关闭数据库

# service mysql status

# service mysql stop

# 启动数据库

service mysql start

4. 修改root密码

#  修改root密码

mysqladmin -u root password 'root'

因为安装好以后的root密码是空,所以需要设置; 如果是测试服务器,那么你可以直接使用root,不重要的密码很多时候可以设置为和用户名一致,以免忘记了又想不起来。

如果是重要的服务器,请使用复杂密码,例如邮箱,各种自由组合的规则的字符等。

我的示例:

[root@localhost ~]# service mysql start

Starting MySQL.170405 17:20:34 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'.

170405 17:20:34 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[  OK  ]

root@localhost ~]# ps aux|grep mysq

root      8824  0.0  0.0  11436  1564 pts/0    S    17:20   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid

mysql     8898  1.1  1.6 824048 134948 pts/0   Sl   17:20   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=/var/lib/mysql/localhost.localdomain.pid

5. 登录数据库

mysql -u root -p

如果是本机,那可以直接使用上面的命令登录,当然,需要输入密码. 如果是其他机器,那么可能需要如下的形式:

mysql -h 127.0.0.1 -P 3306 -u root -p

[root@localhost ~]# mysql

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

Your MariaDB connection id is 3

Server version: 10.1.22-MariaDB MariaDB Server

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

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

MariaDB [(none)]>

MariaDB [(none)]> show variables like 'innodb_file_per%';

+-----------------------+-------+

| Variable_name         | Value |

+-----------------------+-------+

| innodb_file_per_table | ON    |

+-----------------------+-------+

1 row in set (0.00 sec)

6. 简单SQL测试

-- 查看MySQL的状态

status;

-- 显示支持的引擎

show engines;

-- 显示所有数据库

show databases;

-- 切换数据库上下文,即设置当前会话的默认数据库

use test;

-- 显示本数据库所有的表

show tables;

-- 创建一个表

CREATE TABLE t_test (

id int(11) UNSIGNED NOT NULL AUTO_INCREMENT,

userId char(36),

lastLoginTime timestamp,

PRIMARY KEY (id)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 插入测试数据

insert into t_test(userId)

values

('admin')

,('haha')

;

-- 简单查询

select * from t_test;

select id,userId from t_test  where userId='admin' ;

7.  修改数据存放目录

mysql, MariaDB 的默认数据存放在 /var/lib/mysql/ 目录下,如果不想放到此处,或者是想要程序和数据分离,或者是磁盘原因,

需要切换到其他路径,则可以通过修改 datadir系统变量来达成目的.

# 停止数据库

[root@localhost ~]# service mysql stop

Shutting down MySQL...                                     [  OK  ]

# 创建目录,假设没有的话

[root@localhost ~] # mkdir -p /data/mysql

#设置权限

[root@localhost ~]# chown -R mysql:mysql /data/

[root@localhost ~]# ll /data/

total 4

drwxr-xr-x 5 mysql mysql 4096 Apr  5 17:50 mysql

# 按下面的命令重新初始化数据库

[root@localhost ~]# /usr/bin/mysql_install_db --defaults-file=/etc/my.cnf.d/server.cnf --datadir=/data/mysql --user=mysql

# 查看/data/mysql下面的是否生成数据

[root@localhost ~]# ls /data/mysql/

aria_log.00000001  bogon.err  ib_logfile0  localhost.localdomain.err  performance_schema

aria_log_control   ibdata1    ib_logfile1  mysql                      test

# 其实查看 /etc/my.cnf 文件可以发现

# MariaDB 的此文件之中只有一个包含语句

# 所以需要修改的配置文件为 /etc/my.cnf.d/server.cnf

cp /etc/my.cnf.d/server.cnf /etc/my.cnf.d/server.cnf_original

vim /etc/my.cnf.d/server.cnf

然后 按 i 进入编辑模式,可以插入相关内容.使用键盘的上下左右键可以移动光标, 编辑完成以后,按 ESC 退出编辑模式(进入命令模式), 然后输入命令:wq 保存并退出

我的示例:

[root@localhost ~]# cat /etc/my.cnf.d/server.cnf

#

# These groups are read by MariaDB server.

# Use it for options that only the server (but not clients) should see

#

# See the examples of server my.cnf files in /usr/share/mysql/

#

# this is read by the standalone daemon and embedded servers

[server]

# this is only for the mysqld standalone daemon

[mysqld]

datadir=/data/mysql                            #设置/data/mysql为新文件的数据目录

socket=/var/lib/mysql/mysql.sock

#

# * Galera-related settings

#

[galera]

# Mandatory settings

#wsrep_on=ON

#wsrep_provider=

#wsrep_cluster_address=

#binlog_format=row

#default_storage_engine=InnoDB

#innodb_autoinc_lock_mode=2

#

# Allow server to accept connections on all interfaces.

#

#bind-address=0.0.0.0

#

# Optional setting

#wsrep_slave_threads=1

#innodb_flush_log_at_trx_commit=0

# this is only for embedded server

[embedded]

# This group is only read by MariaDB servers, not by MySQL.

# If you use the same .cnf file for MySQL and MariaDB,

# you can put MariaDB-only options here

[mariadb]

# This group is only read by MariaDB-10.1 servers.

# If you use the same .cnf file for MariaDB of different versions,

# use this group for options that older servers don't understand

[mariadb-10.1]

#重启MySQL

[root@localhost ~]# service mysql start

Starting MySQL.170405 17:50:20 mysqld_safe Logging to '/data/mysql/localhost.localdomain.err'.

170405 17:50:20 mysqld_safe Starting mysqld daemon with databases from /data/mysql

[  OK  ]

提示:

/usr/bin/mysqld_safe_helper: Can't create/write to file '/data/mysql/bogon.err' (Errcode: 13 "Permission denied")

ERROR!

害苦了我,多方查找才发selinx开启这呢,果断禁用,然后重启操作系统:OK!!!

vim /etc/sysconfig/selinux

SELINUX=disabled

[root@localhost ~]# mysql

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

Your MariaDB connection id is 3

Server version: 10.1.22-MariaDB MariaDB Server

Copyright (c) 2000, 2016, 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               |

+--------------------+

4 rows in set (0.00 sec)

7.1 创建慢查询日志文件

既然上面指定了慢查询日志文件,我后来看了下MariaDB的err日志,发现MariaDB不会自己创建该文件,所以我们需要自己创建,并修改相应的文件权限(比如 MySQL 采用 mysql用户,可能我们使用 root用户创建的文件,此时要求慢查询日志文件对mysql用户可读可写就行。)

touch /usr/local/ieternal/mysql_data/slow_query_log.log

chmod 666 /usr/local/ieternal/mysql_data/slow_query_log.log

然后重新启动MySQL.

service mysql start

8、mysql初始设置

1、删除匿名用户

mysql> delete from mysql.user where user='';

2、设置root密码

1)、

mysqladmin -u root password "newpass"

2)、

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

3)、

mysql> UPDATE mysql.user SET Password = PASSWORD('db@pass123') WHERE user = 'root';

mysql> FLUSH PRIVILEGES;

4)、在丢失root密码的时候,可以这样

      mysqld_safe --skip-grant-tables&

      mysql -u root mysql

mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';

      mysql> FLUSH PRIVILEGES;

mysql> grant all on *.* to pancou@'%' identified by 'pancou';

转载于:https://blog.51cto.com/lijianmin2008/1925080

CentOS安装并设置MariaDB相关推荐

  1. CentOS安装网卡设置

    1.以centos为例,我安装的是centos 6.9 ,vmware版本是8.0  2.下载方式:百度搜索,vmware下载破解版或者带注册码的:centos 官网或者其它渠道下载iso镜像文件都可 ...

  2. centos安装完设置IP地址

    1.查看Centos当前ip地址(局域网内),命令:ip addr 2.进入网络配置目录:cd /etc/sysconfig/network-scripts 3.查看所有配置文件:ls #列出文件 4 ...

  3. centos 编译nginx php mariadb,centos7安装nginx+mariadb+php-fpm

    由 dp7f1f9f 创建,最后一次修改 2017-05-22 用CentOS-7-x86_64-Minimal-1611.iso最小化安装一个centos7,安装选项:英文.时区为上海.启用网络(如 ...

  4. 如何在CentOS上设置MariaDB Galera Cluster 10.0

     原作者:Jijo 转载:https://www.unixmen.com/setup-mariadb-galera-cluster-10-0-centos/ 如何在CentOS上设置MariaDB G ...

  5. Discuz 安装全流程 CentOS+Docker+PHP+Nginx+Mariadb

    仅供技术研究,并非最简单的Discuz安装方法 文章目录 1 Docker 安装 2 MariaDB 安装 3 PHP 安装 4 Nginx 安装 5 Discuz 安装 5.1 安装文件部署 5.2 ...

  6. 虚拟机安装CentOS以及SecureCRT设置【完美无错版】

    一.CentOS简介 CentOS是Linux的发行版之一,它安全.稳定.高效,是我最喜欢的Linux发行版之一.CentOS根据Red Hat Enterprise Linux开放源代码编译而成,与 ...

  7. linux设置基础软件仓库时,安装centos系统时设置基础软件仓库出错

    安装centos系统时设置基础软件仓库出错,公钥,命令,视频教程,器上,提示 安装centos系统时设置基础软件仓库出错 易采站长站,站长之家为您整理了安装centos系统时设置基础软件仓库出错的相关 ...

  8. centos安装最新的visual studio code并设置中文

    centos上安装最新版本的visual studio code 安装与设置中文 有两种方法 第一种,在官网上下载这个安装包然后双击,会自动跳转到应用商店安装 官网 https://code.visu ...

  9. mariadb安装_MariaDB CentOS 安装的时候如何确定 Repo 地址

    在CentOS 安装 MariaDB 数据库的时候,yum 安装显示没有匹配的安装包. 我们应该如何配置能够让安装成功呢? 你需要在你的 CentOS 中编辑 /etc/yum.repos.d/Mar ...

  10. Centos 安装FTP配置目录权限,iptables设置ftp服务

    Centos 安装FTP配置目录权限,iptables设置ftp服务 2012-07-06 admin Leave a comment Go to comments CentOS 安装vsftpd,设 ...

最新文章

  1. Python创建daemon
  2. 信息安全意识电子期刊第八期
  3. ffmpeg-- audio decoder
  4. python 回溯法 01背包问题_Python回溯法解决01背包问题
  5. 数据结构-循环单链表之魔术师发牌问题
  6. 算法(伪代码)的书写
  7. 解决Qt5 Creator无法切换输入法(fcitx),Ubuntu中不能使用搜狗输入法录入汉字问题...
  8. linux at24测试程序,linux 2.6下eeprom at24c08 i2c设备驱动(new style probe方式)
  9. 白鹭引擎定时器代码实例
  10. 使用证书创建request请求
  11. 将Git子模块更新为最新的原始提交
  12. HTML5实践 -- 介绍css3中的几个属性:text-shadow、box-shadow 和 border-radius
  13. Understand-4.0.877-Linux-64bit.tgz最新版本2017年源代码阅读利器,养眼theme之配置
  14. 浅谈集群、分布式、微服务的异同
  15. C语言之浅析网络包解析
  16. 考试一个程序员,1f=0.1
  17. cocostudio
  18. STM32F091 can通信配置,can波特率计算方法
  19. java 自定义函数_Java自定义函数调用方法解析
  20. Eclipse SVN提交代码ClientException异常解决

热门文章

  1. java 反射 框架_Java——利用反射实现框架类
  2. 中南大学计算机学院伍逸凡,关于公布2017年湖南省大学生力学竞赛等15项学科竞赛结果的通知...
  3. mysql 向量写法_mysql – 你如何在Ruby中处理一个非常大的向量?
  4. C++指针、空指针、野指针使用的一些总结
  5. 中国程序员最爱读错的70个英文单词!注有正解
  6. [并发]线程池关闭的问题
  7. 【零基础入门】 css学习笔记(5) 浮动
  8. 关于人工智能你需要了解的事
  9. IMU、INS、DGPS和POS
  10. iBatis.Net系列(五)-providers.config-