首页 > 代码库 > 安装配置mariadb-10.1.19

安装配置mariadb-10.1.19

本文参考:http://chenzehe.iteye.com/blog/1266260  感谢原作者的分享!

 

首先安装/更新一些编译时会用到的基础包

[root@localhost local]# yum -y install gcc gcc-c++ make cmake ncurses ncurses-devel libxml2 libxml2-devel openssl-devel bison bison-devel

mariadb下载: ftp://mirrors.fe.up.pt/pub/mariadb/mariadb-10.1.20/source/mariadb-10.1.20.tar.gz

编译安装MariaDB10.1.x的版本需要gcc支持c++11,不懂的朋友可以看我另外一篇文章:源码安装GCC-4.9.2

 

1、创建mysql用户

[root@localhost local]# groupadd mysql 
[root@localhost local]# useradd -s /sbin/nologin -g mysql -M mysql #不允许mysql用户登录

2、创建数据存放目录

[root@localhost local]# mkdir -pv /data/dbdata

[root@localhost local]# mkdir -pv /data/innodb
[root@localhost local]# chown -R mysql.mysql /data/ #修改目录权限为mysql

3、安装mariadb

[root@localhost mariadb-10.1.19]#
cmake -DMYSQL_UNIX_ADDR=/tmp/mysql.sock-DSYSCONFDIR=/usr/local/mysql-DMYSQL_TCP_PORT=3306-DEXTRA_CHARSETS=all-DMYSQL_USER=mysql-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DMYSQL_DATADIR=/data/dbdata-DWITH_XTRADB_STORAGE_ENGINE=1-DWITH_FEDERATEDX_STORAGE_ENGINE=1-DWITH_ARCHIVE_STORAGE_ENGINE=1-DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_ARCHIVE_STPRAGE_ENGINE=1-DWITH_BLACKHOLE_STORAGE_ENGINE=1-DWIYH_READLINE=1-DWIYH_SSL=system-DVITH_ZLIB=system-DWITH_LOBWRAP=0-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci

 

[root@localhost mariadb-10.1.19]# make
[root@localhost mariadb-10.1.19]# make install

 到这里MariaDB已经算是安装上了,进行配置就可以使用了。本人在这里用的是多实例配置方法

 1、初始化数据目录

  #把用到的工具添加到/usr/bin目录

[root@localhost mysql]# ln -s /usr/local/mysql/bin/mysqld_multi /usr/bin/mysqld_multi

[root@localhost mysql]#
ln -s /usr/local/mysql/scripts/mysql_install_db /usr/bin/mysql_install_db
[root@localhost mysql]#./scripts/mysql_install_db --datadir=/data/dbdata --user=mysql

 2、配置多实例数据库配置文件

  a)修改my.cnf文件

[mysqld_multi]
 mysqld     = /usr/local/mysql/bin/mysqld_safe
 mysqladmin = /usr/local/mysql/bin/mysqladmin
 user       = mysql
 
 # The MySQL server
 [mysqld6033]
 port        = 6033
 #bind-address    = 127.0.0.1
 socket        = /tmp/mysql.sock.6033
 
 datadir     = /data/dbdata
 pid-file    = /data/dbdata/my.pid
 skip-external-locking
 skip-name-resolve
 interactive_timeout=86400
 wait_timeout=86400
 
 key_buffer = 384M
 max_allowed_packet = 4M
 table_cache = 8192
 sort_buffer_size = 2M
 read_buffer_size = 2M
 myisam_sort_buffer_size = 64M
 thread_cache = 32
 query_cache_size = 64M
 thread_concurrency = 32
 max_connection = 150
 max_connect_errors=400
 max_heap_table_size = 64M
 open_files_limit=2048
 slow_query_log = 1
 long_query_time = 2
 slow-query-log-file = /data/dbdata/slowquery.sql
 log-bin        = /data/dbdata/replication
 server-id    = 100
 #master-host            =    192.168.0.100
 #master-user            =    repuser
 #master-password        =    repuser123
 #master-port            =    6033
 #master-connect-retry   =    30
 log-slave-updates
 skip-slave-start
 character-set-server = utf8
 collation_server = utf8_general_ci
 master-info-file = /data/dbdata/master.info
 
 # Uncomment the following if you are using InnoDB tables
 innodb_data_home_dir = /data/innodb
 innodb_data_file_path = ibdata1:200M;ibdata2:200M;ibdata3:200M;ibdata4:200M;ibdata5:200M
 innodb_log_group_home_dir = /data/innodb/
 innodb_log_arch_dir = /data/innodb/
 innodb_buffer_pool_size = 700M 
 innodb_additional_mem_pool_size = 256M 
 innodb_log_file_size = 256M 
 innodb_log_buffer_size = 32M 
 innodb_flush_log_at_trx_commit = 0
 innodb_lock_wait_timeout = 50
 
 default_storage_engine = innodb

 

3、启动多实例数据库

#将/usr/local/mysql/bin加到$PATH环境变量里  
[root@localhost mysql]# vi /etc/profile

export PATH=/usr/local/mysql/bin:$PATH  #插入到最后一行

#启动mysql
[root@localhost mysql]# mysqld_multi start 6033 –user  #6033是my.cnf里设置的端口

在启动的时候会加载innodb,中途不能重启,否则会出现如下错误

151114 00:59:38  mysqld started

151114  0:59:38 [Warning] option ‘thread_stack‘: unsigned value 126976 adjusted to 131072

InnoDB: No valid checkpoint found.

InnoDB: If this error appears when you are creating an InnoDB database,

InnoDB: the problem may be that during an earlier attempt you managed

InnoDB: to create the InnoDB data files, but log file creation failed.

InnoDB: If that is the case, please refer to

InnoDB: http://dev.mysql.com/doc/refman/5.0/en/error-creating-innodb.html

151114  0:59:38 [ERROR] Default storage engine (InnoDB) is not available

151114  0:59:38 [ERROR] Aborting

151114  0:59:38 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

151114 00:59:38  mysqld ended

 

删除innodb文件夹,重新启动就可以了

 

安装配置mariadb-10.1.19