MariaDB tar包安装 配置
MariaDB起初是MySQL的一个复刻版,由社区开发,有商业支持,旨在继续保持在GUN GPL下开源。MariaDB的开发是由MySQL的一些原始开发者领导的,他们担心甲骨文收购MySQL后会不继续开源。
MariaDB官网:https://mariadb.org/
一.获取安装包并解压
获取安装包的方式有很多,可以wget,也可以直接下载到本地,以目前最新的版本为例,下载地址为:https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/bintar-linux-x86_64/mariadb-10.5.8-linux-x86_64.tar.gz
下载完成之后,tar解压,例如
[root@localhost opt]# pwd /opt # 下载 [root@localhost opt]# wget https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/bintar-linux-x86_64/mariadb-10.5.8-linux-x86_64.tar.gz # 解压 [root@localhost opt]# tar -zxf mariadb-10.5.8-linux-x86_64.tar.gz [root@localhost opt]# ls mariadb-10.5.8-linux-x86_64 mariadb-10.5.8-linux-x86_64.tar.gz
# 解压后可以把文件夹重命名为想要的basedir
[root@localhost opt]# mv mariadb-10.5.8-linux-x86_64 mariadb-10.5.8-33068
我们可以看一下basedir的结构
[root@localhost mariadb-10.5.8-33068]# ls bin CREDITS include lib mysql-test README-wsrep share support-files COPYING EXCEPTIONS-CLIENT INSTALL-BINARY man README.md scripts sql-bench THIRDPARTY
里面比较常用重要的有bin,scripts,support-files这几个文件夹
bin目录下面,是一些可执行程序,例如mariabackup(备份还原工具,后面单独分析),mysql(客户端工具),mysqladmin,mysqlbinlog(日志分析工具),mysqldump(备份还原)等等
scripts目录下面是数据库初始化工具,目前是mariadb-install-db和mysql_install_db,它两其实是一样的
support-files目录下 mysql.server可作为启动程序
二.准备用户和组,datadir和basedir
basedir即为上一步的/opt/mariadb-10.5.8-33068
datadir我选择的是/data01/data/data33068需要注意的是,给datadir要赋予正确的用户和组权限,否则会出现 Permission denied 问题
[root@localhost opt]# groupadd mysql [root@localhost opt]# useradd -g mysql mysql [root@localhost data]# mkdir /data01/data/data33068
[root@localhost data]# chown -R mysql.mysql /data01/data/data33068
三.准备配置文件并使用配置文件初始化
初始化的时候,使用my.cnf,不使用默认配置
使用自定义my.cnf的时候,需要注意my.cnf的读取顺序, /etc/my.cnf /etc/mysql/my.cnf 这两个文件最好不要存在
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
配置文件仅作参考,具体参数后面再分析
[root@localhost mariadb-10.5.8-33068]# cat /opt/mariadb-10.5.8-33068/my.cnf [client] port = 33068 socket = /data01/data/data33068/mysql33068.sock # The MySQL server [mysqld] port = 33068 socket = /data01/data/data33068/mysql33068.sock skip-external-locking skip_name_resolve thread_handling=pool-of-threads relay_log_recovery=1 low-priority-updates event_scheduler = ON key_buffer_size = 32M max_allowed_packet = 32M table_open_cache = 2048 sort_buffer_size = 8M read_buffer_size = 8M read_rnd_buffer_size = 8M join_buffer_size=8M myisam_sort_buffer_size = 32M thread_cache_size = 2000 wait_timeout =15 max_connections = 99999 max_connect_errors = 9999 max_heap_table_size = 8M group_concat_max_len = 102400 tmp_table_size = 8M datadir=/data01/data/data33068 log-error=/data01/data/data33068/mysqld33068.log log-bin=33068 server-id = 1 relay-log = relay-bin relay-log-index = relay-bin binlog_format=row expire_logs_days=4 innodb_file_per_table=1 innodb_data_home_dir=/data01/data/data33068 innodb_data_file_path=ibdata1:1G:autoextend innodb_buffer_pool_instances=4 innodb_buffer_pool_size = 512M innodb_log_group_home_dir=/data01/data/data33068 innodb_log_files_in_group = 3 innodb_log_file_size =1G innodb_log_buffer_size = 50M innodb_flush_method=O_DIRECT innodb_thread_concurrency=16 innodb_max_dirty_pages_pct=75 innodb_flush_log_at_trx_commit = 2 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash prompt=MariaDB [\d]> [myisamchk] key_buffer_size = 25M sort_buffer_size = 25M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
初始化
[root@localhost mariadb-10.5.8-33068]# /opt/mariadb-10.5.8-33068/scripts/mysql_install_db --defaults-file=/opt/mariadb-10.5.8-33068/my.cnf --basedir=/opt/mariadb-10.5.8-33068/ --datadir=/data01/data/data33068/ --user=mysql
若初始化失败,需要根据提示在错误日志里面找问题
四.配置启动脚本并启动
[root@localhost support-files]# cp -rp /opt/mariadb-10.5.8-33068/support-files/mysql.server /etc/init.d/mysqld33068
# copy完成之后需要更改下面三行(行号仅供参考) 45 basedir=/opt/mariadb-10.5.8-33068 46 datadir=/data01/data/data33068 261 if $bindir/mysqladmin -S /data01/data/data33068/mysql33068.sock ping >/dev/null 2>&1; then
#也可以使用下面语句进行更改
sed -i "s/^basedir\=/basedir\=\"\/opt\/mariadb-10.5.8-33068\"/g" /etc/init.d/mysqld33068
打开服务 /etc/init.d/mysqld33068 start 即可登陆使用,密码为空 /opt/mariadb-10.5.8-33068/bin/mariadb -S /data01/data/data33068/mysql33068.sock -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 6 Server version: 10.5.8-MariaDB-log MariaDB Server Copyright (c) 2000, 2018, 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.001 sec) MariaDB [(none)]> Ctrl-C -- exit! Aborted