系统环境:CentOS6.6(Final)
MariaDB端口:3309 (因为本机原先已经装的有MySQL了,还不想删除MySQL)
#wget
建立mariadb用户
# groupadd -r mariadb
# useradd -g mariadb -r -M -s /sbin/nologin mariadb //这个mariadb用户不能登录
依赖组件
# yum -y install gcc gcc-c++ make cmake ncurses ncurses libxml2 libxml2-devel openssl-devel bison bison-devel
# tar zxvf mariadb-10.0.20.tar.gz
# cd mariadb-10.0.20
# cmake . -DMYSQL_UNIX_ADDR=/tmp/mariadb.sock -DSYSCONFDIR=/home/local/mariadb -DMYSQL_TCP_PORT=3309 -DEXTRA_CHARSETS=all -DMYSQL_USER=mariadb -DCMAKE_INSTALL_PREFIX=/home/local/mariadb -DMYSQL_DATADIR=/home/data/mariadb -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
# make -j 4
# make install
把MariaDB服务加入系统环境变量:在最后添加下面这一行
# vim /etc/profile
export PATH=$PATH:/home/local/mariadb/bin
# source /etc/profile
复制配置文件
# cp /home/local/mariadb/support-files/my-large.cnf /home/local/mariadb/my.cnf
初始化数据库
# /home/local/mariadb/scripts/mysql_install_db --basedir=/home/local/mariadb --datadir=/home/data/mariadb --user=mariadb --defaults-file=/home/local/mariadb/my.cnf
复制服务启动脚本
# cp /home/local/mariadb/support-files/mysql.server /etc/init.d/mariadb
# vim /etc/init.d/mariadb
找到
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
行,改为
$bindir/mysqld_safe --defaults-file=/home/local/mariadb/my.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
即添加了--defaults-file=/home/local/mariadb/my.cnf
保存退出
# chmod +x /etc/init.d/mariadb
# chkconfig mariadb on
配置/home/local/mariadb/my.cnf
在[mysqld]模块添加下面的几行:
log-error = /home/logs/mariadb_error.log
pid-file = /home/local/mariadb/mariadb.pid
user=mariadb
datadir = /home/data/mariadb
basedir = /home/local/mariadb
新增加mysqld_safe块
[mysqld_safe]
log-error= /home/logs/mariadb_error.log
pid-file=/home/local/mariadb/mariadb.pid
启动前修下目录权限
# chown -R mariadb:mariadb /home/data/mariadb
# chown -R mariadb:mariadb /home/data/mariadb/.
# chown -R mariadb:mariadb /home/local/mariadb
# chown -R mariadb:mariadb /home/local/mariadb/.
启动MariaDB:
# /etc/init.d/mariadb start
注:如果启动失败,查看下/home/logs/mariadb_error.log文件看报什么错,修正即可。
设置root的密码
#/home/local/mariadb/bin/mysqladmin -u root password '123456'
进入MariaDB的shell下
[root@localhost mariadb]# /home/local/mariadb/bin/mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.0.20-MariaDB Source distribution
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show engines\G;
*************************** 1. row ***************************
Engine: InnoDB
Support: DEFAULT
Comment: Percona-XtraDB, Supports transactions, row-level locking, and foreign keys
Transactions: YES
XA: YES
Savepoints: YES
*************************** 2. row ***************************
Engine: MRG_MyISAM
Support: YES
Comment: Collection of identical MyISAM tables
Transactions: NO
XA: NO
Savepoints: NO
*************************** 3. row ***************************
Engine: CSV
Support: YES
Comment: CSV storage engine
Transactions: NO
XA: NO
Savepoints: NO
*************************** 4. row ***************************
Engine: BLACKHOLE
Support: YES
Comment: /dev/null storage engine (anything you write to it disappears)
Transactions: NO
XA: NO
Savepoints: NO
*************************** 5. row ***************************
Engine: MyISAM
Support: YES
Comment: MyISAM storage engine
Transactions: NO
XA: NO
Savepoints: NO
*************************** 6. row ***************************
Engine: MEMORY
Support: YES
Comment: Hash based, stored in memory, useful for temporary tables
Transactions: NO
XA: NO
Savepoints: NO
*************************** 7. row ***************************
Engine: ARCHIVE
Support: YES
Comment: Archive storage engine
Transactions: NO
XA: NO
Savepoints: NO
*************************** 8. row ***************************
Engine: PERFORMANCE_SCHEMA
Support: YES
Comment: Performance Schema
Transactions: NO
XA: NO
Savepoints: NO
*************************** 9. row ***************************
Engine: FEDERATED
Support: YES
Comment: FederatedX pluggable storage engine
Transactions: YES
XA: NO
Savepoints: YES
*************************** 10. row ***************************
Engine: Aria
Support: YES
Comment: Crash-safe tables with MyISAM heritage
Transactions: NO
XA: NO
Savepoints: NO
10 rows in set (0.00 sec)
ERROR: No query specified