MariaDB编译安装和开始使用入门

MariaDB是MySQL创始人基于MySQL的另起的一个分支,其功能上绝大部分兼容于MySQL。MariaDB的官网为https://mariadb.com/。

MySQL基本架构如下所示:

MySQL核心组件:

连接池作用:认证、线程、连接数限制,内存检查、缓存;

SQL接口:DML(数据操作语言),DDL(数据定义语言)、关系型数据库的基本抽象;

Parser(分析器):查询转换、对象权限检查;

优化器:访问路径、性能相关的统计数据;

Caches和buffers:与存储引擎自身相关的I/O性能提升工具;

存储引擎: MyiSAM、InnoDB、NDB、Archive、Memory、Merge、Federated、CVS、Blackholl、Aria、Sphinx、TokuDB

安装方式有3种:

rpm包:操作系统供应商、MySQL官网的

通用二进制格式:MySQL官网上也有

源码包:MySQL官网提供

环境: centos 6.6

下面以mariadb-10.0.13.tar.gz源码包方式安装,下载源码包后,放在/usr/local/src/目录下,源码包编译安装需要先安装好Development tools、Server Platform Development这两个包组。

使用#yum groupinstall -y "Server Platform Development" "Development tools"安装

安装好后,把源码包解压放到/usr/local目录下

[[email protected] src]# tar xf mariadb-10.0.13.tar.gz -C /usr/local/

为安装前准备好环境,包括如下步骤:

1.创建没有登录权限的MySQL系统用户

[[email protected] local]# useradd -r -s /sbin/nologin mysql

2.创建MySQL数据目录(为了数据安全性,一般都是单独存放在一个硬盘且有高可用的RAID上),修改数据目录的属主和属组为mysql

这里使用lvm来演示

[[email protected] local]# lvcreate -L 10G -n data vg_lvm   创建10G的逻辑卷

[[email protected] local]# mkfs.ext4 /dev/vg_lvm/data       格式化刚创建的逻辑卷

[[email protected] local]# mount /dev/vg_lvm/data /mysql    挂载
    [[email protected] local]# mkdir /mysql/data                创建数据目录
    [[email protected] local]# chown -R mysql.mysql /mysql/data  改变属主和属组

MariaDB 10.0.13需要通过cmake来进行编译,需要先安装cmake

#yum install -y cmake

查看一下使用帮助

[[email protected] mariadb-10.0.13]# cmake -LH
    .......
    // Path to a library.
    AIO_LIBRARY:FILEPATH=AIO_LIBRARY-NOTFOUND
    
    // Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel
    CMAKE_BUILD_TYPE:STRING=RelWithDebInfo
    
    // install prefix
    CMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql
    
    // Set to true if this is a community build
    COMMUNITY_BUILD:BOOL=ON
    
    // Compile CONNECT storage engine with LIBXML2 support
    CONNECT_WITH_LIBXML2:BOOL=ON
    
    // Compile CONNECT storage engine with remote MySQL connection support
    CONNECT_WITH_MYSQL:BOOL=ON
    .........

启用ssl和使用Sphinx存储引擎
    [[email protected] mariadb-10.0.13]# cmake . -DMYSQL_DATADIR=/mysql/data -DWITH_SSL=system -DWITH_SPHINX_STORAGE_ENGINE=1
    ...
    -- Configuring done
    -- Generating done
    CMake Warning:
      Manually-specified variables were not used by the project:
    
        MYSAL_DATADIR
    
    
    -- Build files have been written to: /usr/local/mariadb-10.0.13
    说明配置ok
    
    出现如下错误提示:
    -- Could NOT find LibXml2 (missing:  LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR)
    Warning: Bison executable not found in PATH
    需要安装libxml2-devel

[[email protected] mariadb-10.0.13]# make   执行时间看机器性能

[[email protected] mariadb-10.0.13]# make install

执行过程会有进度显示的达到100%后就ok了

[[email protected] mariadb-10.0.13]# cd ../mysql/
    [[email protected] mysql]# ls
    bin             CREDITS  EXCEPTIONS-CLIENT  lib         README   sql-bench
    COPYING         data     include            man         scripts  support-files
    COPYING.LESSER  docs     INSTALL-BINARY     mysql-test  share

support-files目录下有配置文件和启动文件   与通用二进制安装一样

scripts 有数据库初始化文件

导出头文件

导出二进制文件

导出man文档

[[email protected] mysql]# ln -sv /usr/local/mysql/include /usr/include/mysql
    `/usr/include/mysql‘ -> `/usr/local/mysql/include‘
    [[email protected] mysql]# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
    [[email protected] mysql]# . /etc/profile.d/mysql.sh
    [[email protected] mysql]# vim /etc/man.config

在MANPATH出添加

MANPATH /usr/local/mysql/man

[[email protected] mysql]# cp support-files/my-large.cnf /etc/my.cnf

修改配置文件添加数据目录为/mysql/data

[[email protected] mysql]# vim /etc/my.cnf  在mysqld段下添加datadir=/mysql/data

[[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld  复制开机启动文件
    [[email protected] mysql]# ls -l /etc/rc.d/init.d/mysqld
    -rwxr-xr-x 1 root root 12052 Apr 16 11:20 /etc/rc.d/init.d/mysqld
    [[email protected] mysql]# chkconfig --add mysqld
    [[email protected] mysql]# chkconfig --list mysqld
    mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off

初始化mysql
    [[email protected] mysql]# scripts/mysql_install_db --user=mysql --datadir=/mysql/data

启动mysql

[[email protected] mysql]# service mysqld start
    Starting MySQL. SUCCESS!

连接mysql

[[email protected] mysql]# mysql
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 4
    Server version: 10.0.13-MariaDB-log Source distribution
    
    Copyright (c) 2000, 2014, Oracle, SkySQL 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)
    。。。。。。。。。

MariaDB [(none)]> show engines\G      sphinx存储引擎启用

Savepoints: NO
    *************************** 8. row ***************************
          Engine: SPHINX
         Support: YES
         Comment: Sphinx storage engine 2.1.5-release
    Transactions: NO
              XA: NO
      Savepoints: NO
    8 rows in set (0.00 sec)
    
    MariaDB [(none)]> show global variables like ‘%ssl%‘;
    +---------------+----------+
    | Variable_name | Value    |
    +---------------+----------+
    | have_openssl  | YES      |   ssl功能支持了,只是还未启用
    | have_ssl      | DISABLED |
    | ssl_ca        |          |
    | ssl_capath    |          |
    | ssl_cert      |          |
    | ssl_cipher    |          |
    | ssl_crl       |          |
    | ssl_crlpath   |          |
    | ssl_key       |          |
    +---------------+----------+
    9 rows in set (0.00 sec)

MySQL的数据文件包括:文件和日志
        文件:数据文件和索引文件
        日志:事务日志、二进制日志、查询日志、慢查询日志、错误日志、中继日志
    
    MySQL的服务器变量查看:
        SHOW {GLOBAL|SESSION} VARIABLES [LIKE CLAUSE];
    
    MySQL的状态变量查看:
        SHOW {GLOBAL|SESSION} STATUS [LIKE CLAUSE];

MySQL Logical Archtecture

所有连接都是通过线程来实现的,线程池满了以后,连接需要在队列中等待
    myisam存储引擎不支持事务(读多写少性能较好)
    
    安装和访问MySQL Server:
        初始化:
            给root用户设置密码:
                mysql>SET PASSWORD FOR ‘username‘@‘host‘ = PASSWORD(‘your_password‘);
                更改表数据的方式来设定密码
                mysql>update mysql.user set password=PASSWORD(‘your_password‘) where user=‘username‘ and host=‘hostname or ip‘

命令行方式修改
                #mysqladmin -uUSERNMAE -hHOSTNAME_OR_IP -p password ‘new_password‘

删除匿名用户

mysql>drop  user  user[,user] ...

mysql>delete from tbl_name where where_condition

MariaDB [(none)]> select User,Host,Password from mysql.user;查看当前有哪些用户
    +------+-----------+----------+
    | User | Host      | Password |
    +------+-----------+----------+
    | root | localhost |          |
    | root | hostpc    |          |
    | root | 127.0.0.1 |          |
    | root | ::1       |          |
    |      | localhost |          |
    |      | hostpc    |          |
    +------+-----------+----------+
    6 rows in set (0.00 sec)

删除匿名用户

MariaDB [(none)]> drop user ‘‘@localhost;
    Query OK, 0 rows affected (0.03 sec)
    
    MariaDB [(none)]> delete from mysql.user where User=‘‘;
    Query OK, 1 row affected (0.00 sec)
    
    MariaDB [(none)]> select User,Host,Password from mysql.user;
    +------+-----------+----------+
    | User | Host      | Password |
    +------+-----------+----------+
    | root | localhost |          |
    | root | hostpc    |          |
    | root | 127.0.0.1 |          |
    | root | ::1       |          |
    +------+-----------+----------+
    4 rows in set (0.00 sec)

设置MySQL用户密码
    MariaDB [(none)]> update mysql.user set password=password(‘123456‘) where user=‘127.0.0.1‘;
    Query OK, 0 rows affected (0.00 sec)
    Rows matched: 0  Changed: 0  Warnings: 0
    
    MariaDB [(none)]> set password for ‘root‘@‘::1‘=password(‘123456‘);
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> update mysql.user set password=password(‘123456‘) where host=‘127.0.0.1‘;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    MariaDB [(none)]> update mysql.user set password=password(‘123456‘) where host=‘hostpc‘;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    MariaDB [(none)]> flush privileges;  刷新授权表
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> select User,Host,Password from mysql.user;
    +------+-----------+-------------------------------------------+
    | User | Host      | Password                                  |
    +------+-----------+-------------------------------------------+
    | root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
    | root | hostpc    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
    | root | 127.0.0.1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
    | root | ::1       | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
    +------+-----------+-------------------------------------------+
    4 rows in set (0.00 sec)

获取帮助:mysqld --verbose --help  会显示所有的MySQL变量,启动MySQL时,可以直接传递给MySQL的选项【有些选项只能在配置文件中用,有的只能在选项中使用】
                --option, -option: 命令行选项
    Usage: mysqld [OPTIONS]    默认读取配置文件的顺序
            Default options are read from the following files in the given order:
            /etc/my.cnf  /etc/mysql/my.cnf  ~/.my.cnf
            --print-defaults        Print the program argument list and exit.
            --defaults-extra-file=#:额外读取的配置文件;Read this file after the global files are read.
    
            --defaults-file=#: 仅读取此处指定的配置文件  Read this file after the global files are read.
    现在每次登陆时都要指定用户名和密码,为其添加一个家目录下的配置文件.my.cnf,在配置文件中指定用户名和密码
    [[email protected] mysql]# mysql
    ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
    [[email protected] mysql]# mysql -u root -p
    Enter password:
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 177
    Server version: 10.0.13-MariaDB-log Source distribution
    
    Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
    
    Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
    
    MariaDB [(none)]> \q
    Bye
    [[email protected] mysql]# cd
    [[email protected] ~]# vim .my.cnf
    [[email protected] ~]# cat .my.cnf  用户名和密码都指定了
    [mysql]
    user = root
    host = localhost
    password = ‘123456‘
    [[email protected] ~]# mysql   登录就不需要提供密码了
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 179
    Server version: 10.0.13-MariaDB-log Source distribution
    
    Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
    
    Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
    
    MariaDB [(none)]>

windows上配置文件位置读取
      With Windows servers the following order of precedence is used:
      %WINDIR%\my.ini, %WINDIR%\my.cnf
      C:\my.ini, C:\my.cnf
      %INSTALLDIR%\my.ini, %INSTALLDIR%\my.cnf
      /path/to/file when --defaults-extra-file=/path/to/file is specified
    会挨个读取所有的配置文件
    
    /usr/local/mysql/bin/目录下,mysqldxx是服务器端程序
    mysqld_safe   线程安全的mysqld,大多数情况下启动的都是mysqld_safe
    mysqld_multi  在MySQL主机上同时启动多个MySQL程序
    mysqlxx是客户端程序,客户端程序是指能够通过mysql协议请求连入服务器端,跟MySQL服务器进行交互
    
    mysql程序的类别:
            服务器端程序:启动并监听于套接字上;mysqld, mysqld_safe, mysqld_multi
            客户端程序:可通过mysql协议连入服务器并发出请求的;mysql, mysqlbinlog, mysqladmin, mysqldump等
            工具程序:运行于服务器进程所在的主机,实现一些管理或维护操作,myisamchk
    
    客户端程序的通用选项:
      -u, --user=   指定用户
      -u root, -uroot, --user=root   短选项和参数之间可以没有空格
      -h, --host=   指定主机
      -p, --password=  指定密码

--protocol=   指定什么方式进行通信
        tcp:
        socket: unix sock  是实现本机通信的,windows上没有实现
        pipe:
        memory:
      --port: 当Protocol是tcp时使用的端口;
      --socket: 相当于--protocol socket
       其它选项:
       -D  DBNAME  登录时,进入到DBNAME
      --database=

mysql客户端程序:mysql
        运行方式有两类:
            交互式模式:
            批模式:mysql < /path/from/somefile.sql

交互式模式:
            命令有两类:
                客户端命令:help可列出所有命令
                    clear, \c: Clear the current input statement. 取消当前命令的执行
                    ego, \G: Send command to mysql server, display result vertically. 垂直显示
                    go, \g:  Send command to mysql server.
                    delimiter, \d:  Set statement delimiter.  设置分隔符
                    quit, exit, \q:      Exit mysql. Same as quit.
                    source, \. /path/from/somefile.sql:  Execute an SQL script file. Takes a file name as an argument.
                  相当于mysql < /path/from/somefile.sql
                    system, \! COMMAND: 运行shell命令  Execute a system shell command.
                    use, \u DB_NAME: 将指定的库设为默认库  Use another database. Takes database name as argument.

服务器端命令:help KEYWORD  需要在命令后加;号
                    SQL语句:
                        DDL   数据库定义语言
                        DML   数据库操作语言

help KEYWORD    查看帮助
        选项:
            -e ‘SQL语句‘  不连入MySQL服务器,直接执行sql语句
            # mysql -e ‘select User,Host,Password from mysql.user;‘
    
    MySQL客户端程序连接服务器时,会首先读取配置文件
    mysql -->mysql protocol (TCP/IP) --> mysqld

mysqladmin工具:mysqladmin - client for administering a MySQL server   是一个客户端工具

mysqladmin [options] command [arg] [command [arg]] ...

子命令:
        create DB_NAME:
            mysqldadmin [options] create DB_NAME;
        drop DB_NAME:  会提示是否删除
        status:
            显示mysqld的简要状态信息,专用选项
    [[email protected] ~]# mysqladmin -u root -p status  需要指定用户和密码登录
    Enter password:
    Uptime: 13838  Threads: 1  Questions: 41  Slow queries: 0  Opens: 4  Flush tables: 1  Open tables: 67  Queries per second avg: 0.002
    [[email protected] ~]# mysqladmin status
    mysqladmin: connect to server at ‘localhost‘ failed
    error: ‘Access denied for user ‘root‘@‘localhost‘ (using password: NO)‘

如果想不输入密码,则可以在.my.cnf配置文件添加一个客户端段

[[email protected] ~]# cat .my.cnf
    [mysql]
    user = root
    host = localhost
    password = ‘123456‘
    [client]  所有客户端工具都可以通过此用户来登录了
    user = root
    host = localhost
    password = ‘123456‘
    [[email protected] ~]# mysqladmin status
    Uptime: 15812  Threads: 1  Questions: 42  Slow queries: 0  Opens: 4  Flush tables: 1  Open tables: 67  Queries per second avg: 0.002

--sleep #: 每间隔1秒显示一次
           # mysqladmin status --sleep 1
           --count #: 显示的次数
           #mysqladmin status --sleep 1 --count 5
        extended-status: 显示mysqld的所有服务器变量和他们的当前值
    [[email protected] ~]# mysqladmin extended-status | grep select
    | Com_insert_select                             | 0                |
    | Com_replace_select                            | 0                |
    | Com_select                                    | 8                |
    | Connection_errors_select                      | 0                |

flush-privileges: 刷新授权表,相当于reload命令
        flush-hosts: 清除dns缓存及被拒绝的客户端列表缓存
        flush-logs: 滚动日志后就会重新开始记录日志, 一般是二进制日志和中继日志
        flush-status: 重置各状态变量
        flush-tables: 关闭当前打开的所有的表文件句柄;如果某文件句柄总被访问,需要等待其访问结束。
        flush-treads: 重置线程缓存;

password: 设置密码
        ping: 测试服务器是否在线

[[email protected] ~]# mysqladmin ping
    mysqld is alive

processlist: 显示当前服务器上的所有线程,每个线程都有其id号
    # mysqladmin processlist
        refresh: 相当于执行flush-hosts和flush-logs

shutdown: 关闭服务器进程 ;

start-slave, stop-slave: 这个是主从复制时会使用到,启动、关闭从服务器线程;

variables: 显示服务器变量

时间: 2024-08-02 06:32:08

MariaDB编译安装和开始使用入门的相关文章

MySQL核心概念及MariaDB编译安装

MariaDB安装方式:      ①rpm包:                os vendor                mysql                通用二进制格式       ②源码包 编译方式安装mariadb: 编译安装MariaDB cmake的重要特性之一是其独立于源码(out-of-source)的编译功能,即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译的影响,因此在同一个源码树上可以进行多次不同的编译,如针对于不同平台

mariadb编译安装脚本

#!/bin/bash#Date:2017-04-23#Author:Allen_Jol#mariadb_install_v1.0.sh#Version:mariadb-10.1.22 MARIADB_VERSION="mariadb-10.1.22.tar.gz"echo "mariadb版本是:$MARIADB_VERSION"PATHWAY=/usr/local/srccd $PATHWAYecho "====================PREP

mariadb编译安装流程

1. 编译前准备环境CentOS7.4编译安装 mariadb-10.2.12.tar.gziptables -vnL #查看防火墙状态systemctl stop firewall #关闭防火墙getenforce #查看SELinux状态setenforce 0 #关闭SELinux rpm -q mariadb-server #检查mariadb是否安装 2. 安装开发相关包组 yum groupinstall 'development tools' yum install bison b

mariadb编译安装

下载源码包 进网站选 5.5 mariadb 传到要安装的主机 解包 tar -zxvf mariadb-5.5.66.tar.gz 安装包 yum install bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-

CentOS 7中mariadb编译安装教程systemctl启动

mariadb做为mysql的替代品 现在centos的新版本yum包已换成mariadb 跟上篇一样只是启动方式改为systemd 安装一些库 yum install gcc gcc-c++ wget net-tools 查看SELinux状态: /usr/sbin/sestatus -v #如果SELinux status参数为enabled即为开启状态;如果为关闭可以跳过修改/etc/selinux/config文件 vi /etc/selinux/config 将SELINUX=enfo

mariadb的编译安装

mariadb编译安装 mariadb-10.0.12.tar.gz 1.安装cmake包 # yum install cmake 2.创建用户,提供数据库目录 # useradd -r -s /sbin/nologin mysql # mkdir -p /mydata/data # chown mysql:mysql /mydata/data 3.编译mariadb # tar xf mariadb-10.0.12.tar.gz # cd mariadb-10.0.12 # cmake .-D

手把手教你编译安装MariaDB

MariaDB是什么? MariaDB是MySQL的一个分支,由于Oracle有可能对MySQL闭源,所以分离了出来(MySQL先后被Sun.Oracle收购). 但是除了作为一个Mysql的“向下替代品”,MariaDB包括的一些新特性使它优于MySQL. 官网说明 The instructions on this page will help you compile MariaDB from source. Links to more complete instructions for sp

编译安装MariaDB源码包

因为MySQL的发展趋势不甚乐观,MariaDB已替代MySQL被CentOS 7做为默认组件,如果想在CentOS 6中使用最新的MariaDB,则需要我们手动安装,其安装方式有三种: 1.RPM包安装 2.二进制包安装 3.源码包安装 下面我们来介绍如何使用源码包来安装MariaDB,系统平台:CentOS 6.5:MariaDB版本:10.0.19 一.获得MariaDB源码包 可以通过MariaDB的官方网站来获得MariaDB的最新源码包,下载地址为:https://downloads

CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境

什么是LNMP? LNMP(别名LEMP)是指由Linux, Nginx, MySQL/MariaDB, PHP/Perl/Python组合成的动态Web应用程序和服务器,它是一组Web应用程序的基础软件包,在这个基础环境上我们可以搭建任何使用PHP/Perl/Python等语言的动态网站,如商务网站.博客.论坛和开源Web应用程序软件等,它是互联网上被广泛使用的Web网站架构之一. 部署方式 从网站规模大小(访问流量.注册用户等)角度来看,LNMP架构可以使用单机部署方式和集群部署方式.单机部