关于MariaDB
MariaDB
是MySQL
的一个分支,由MySQL的创始人Michael Widenius主导开发,当期主要由开源社区在维护,采用GPL授权许可。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。MariaDB以源码
,二进制
及rpm/deb
格式分发。
安装前工作
1.安装开发者工具
[root@centos7 ~]# yum -y groupinstall "development tools"
2.创建mysql用户
[root@centos7 ~]# useradd -r -u 55 -m -d /data -s /sbin/nologin mysql #注意,应创建为系统用户
[root@centos7 ~]# id mysql
uid=55(mysql) gid=55(mysql) groups=55(mysql)
3.获取二进制程序
[root@centos7 ~]# wget http://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.2.8/bintar-linux-x86_64/mariadb-10.2.8-linux-x86_64.tar.gz
[root@centos7 ~]# tar zxvf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/
[root@centos7 ~]# cd /usr/local/
[root@centos7 local]# ls
bin games lib libexec sbin src
etc include lib64 mariadb-10.2.8-linux-x86_64 share
[root@centos7 local]# mv mariadb-10.2.8-linux-x86_64/ mysql #必须重命名为mysql或创建名为mysql的软链接 因为该路径在二进制文件中已定义 不可直接修改
[root@centos7 local]# ls
bin etc games include lib lib64 libexec mysql sbin share src
准备相关文件
1.准备配置文件
[root@centos7 local]# cd mysql/
[root@centos7 mysql]# mkdir /etc/mysql
[root@centos7 mysql]# cp support-files/my-small.cnf /etc/mysql/my.cnf #拷贝官方配置文件,本例中拷贝的为较小数据量的场景配置文件
[root@centos7 mysql]# vim /etc/mysql/my.cnf
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = /data #添加该行。该参数用于指定数据库的磁盘存储路径
2.创建日志文件
[root@centos7 mysql]# cat /etc/my.cnf |grep log
log-error=/var/log/mariadb/mariadb.log
[root@centos7 mysql]# mkdir /var/log/mariadb
[root@centos7 mysql]# touch /var/log/mariadb/mariadb.log
[root@centos7 mysql]# chown -R mysql:mysql /var/log/mariadb/ #至少要保证mysql用户有读写日志的权限
[root@centos7 mysql]# ll /var/log/mariadb/
total 0
-rw-r--r-- 1 mysql mysql 0 Sep 25 09:12 mariadb.log
[root@centos7 mysql]# ll /var/log/mariadb/ -d
drwxr-xr-x 2 mysql mysql 4096 Sep 25 09:12 /var/log/mariadb/
安装数据库
1.初始化mariadb数据库
[root@centos7 mysql]# ./scripts/mysql_install_db --datadir=/data --user=mysq
l #--datadir=数据库磁盘存储目录, --user=以指定用户身份运行,建议使用mysql用户
Installing MariaDB/MySQL system tables in '/data' ...
OK #看到这个字样 意味着初始化成功。需要注意的是,如果没有事先创建日志文件并赋权,此处可能会有warnning警报
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system #要启动mysqld需要拷贝服务脚本
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands: #安全提示
'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h centos7 password 'new-password'
Alternatively you can run: #提示需要运行安全脚本 解决上述的安全提示
'./bin/mysql_secure_installation'
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/data'
You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
[root@centos7 mysql]# ls /data
aria_log.00000001 ibdata1 multi-master.info mysql-bin.000003
aria_log_control ib_logfile0 mysql mysql-bin.index
centos7.pid ib_logfile1 mysql-bin.000001 performance_schema
ib_buffer_pool ibtmp1 mysql-bin.000002
2.准备服务脚本
[root@centos7 mysql]# cp support-files/mysql.server /etc/init.d/mysqld #拷贝服务脚本到init.d
[root@centos7 mysql]# chkconfig --add mysqld #添加开机自启服务
[root@centos7 mysql]# chkconfig mysqld --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by nativ
e
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3.添加服务至PATH
[root@centos7 bin]# cd bin
[root@centos7 bin]# mysql #此时会提示命令不存在
-bash: mysql: command not found
[root@centos7 bin]# vim /etc/profile.d/mysqld.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@centos7 bin]# . /etc/profile.d/mysqld.sh #重新读取PATH值 使其修改生效;此时,我们可以便可以通过二进制安装包自带的帮助手册`mysql --help`或`man mysql`来获取更多帮助。
4.启动mariadb
[root@centos7 bin]# service mysqld start
Starting mysqld (via systemctl): [ OK ]
[root@centos7 bin]# ss -tnl #查看3306端口是否已处于监听状态
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 80 :::3306 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
安装后工作
1.运行安全脚本
[root@centos7 bin]# ./mysql_secure_installation
2.连接数据库
[root@centos7 bin]# mysql -uroot -p
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)