1 下载linux下安装二进制包
以下以安装mariadb-10.5.8-linux-systemd-x86_64.tar.gz为例
2 安装步骤
1)解压缩安装包
tar -xvzf mariadb-10.5.8-linux-systemd-x86_64.tar.gz
建立一个软连接(方便后续操作)
ln -s /opt/mariadb-10.5.8-linux-systemd-x86_64 /opt/maridb
2)修改配置文件my.cnf
先在/opt/maridb建立一个配置文件目录、日志目录、数据目录、运行目录
cd /opt/mariadb
mkdir etc
cp /etc/my.cnf /etc/
mkdir data
mkdir log
mkdir run
修改配置文件my.cnf
[mysqld]
datadir=/opt/mariadb/data
socket=/opt/mariadb/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
port=3306
#user=appadmin
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/opt/mariadb/log/mariadb.log
pid-file=/opt/mariadb/run/mariadb.pid
#
# include all files from the config directory
3)初始化系统数据库
cp /script/mariadb-install-db ../ (如果不copy到上一级目录,启动脚本可能会报一个路径错误)
./mariadb-install-db --defaults-file=/opt/mariadb/etc/my.cnf --user=appadmin
4)启动数据库实例
- 如果同一系统中存在多个MariaDB实例,可以通过mysqld_safe程序启停MariaDB服务。
/var/lib/mysql是MariaDB服务的默认数据目录,我们可以配置指定其他数据目录。 - 此外,还可以指定配置文件,使用配置文件启停MariaDB服务。
#利用mysqld_safe启动
ln -s /tmp/mysql.sock /opt/mariadb/mysql.sock (如果/tmp目录下没这个文件,启动会出一个错,具体可以看错误提示)
cd /opt/mariadb/bin/
执行以下脚本:
./mysqld_safe --defaults-file=/opt/mariadb/etc/my.cnf &
或
./mysqld_safe --datadir=../data/ --socket=../mysql.sock --port=3306 --user=appadmin&
查看3306端口已经监听。
netstat -nltp | grep 3306
连接数据库
./mariadb -u appadmin -p
或
#通过本地socket方式登录
mysql -S /opt/mariadb/mysql.sock -uappadmin
停止数据库实例
#利用mysqladmin停止服务
./mysqladmin -S ../mysql.sock shutdown