下载安装包
wget https://mirrors.ustc.edu.cn/mariadb/mariadb-10.6.14/bintar-linux-systemd-x86_64/mariadb-10.6.14-linux-systemd-x86_64.tar.gz
解压
tar xvf mariadb-10.6.14-linux-systemd-x86_64.tar.gz
移动至/opt
mv mariadb-10.6.14-linux-systemd-x86_64 /opt/mariadb
初始化配置文件
echo '!includedir /etc/my.cnf.d' > /etc/my.cnf
mkdir /etc/my.cnf.d
cat <<eof|tee /etc/my.cnf.d/server.cnf
[mysqld]
#base
user=mysql
port=3306
basedir=/opt/mariadb
datadir=/opt/mariadb/data
socket=/opt/mariadb/data/mysql.socket
pid-file=/opt/mariadb/data/mysqld.pid
#log
log_error=/opt/mariadb/log/mariadb.log
slow_query_log=on
slow_launch_time=1
slow_query_log_file=/opt/mariadb/log/mariadb-slow.log
#Optimization
group_concat_max_len=204800
max_connections=500
max_connect_errors=1000
max_allowed_packet=1024M
innodb_buffer_pool_size=1024M
eof
cat <<eof|tee /etc/my.cnf.d/client.cnf
[client]
socket=/opt/mariadb/data/mysql.socket
eof
初始化目录
mkdir /opt/mariadb/data
mkdir /opt/mariadb/log
设置权限
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
groupadd mysql
useradd mysql -r -g mysql -s /bin/false
chown -R mysql:mysql /opt/mariadb
设置环境变量
echo 'export PATH=$PATH:/opt/mariadb/bin' > /etc/profile.d/mariadb.sh
source /etc/profile
初始化数据库
/opt/mariadb/scripts/mariadb-install-db
设置服务
cp /opt/mariadb/support-files/systemd/mariadb.service /etc/systemd/system
sed -i \
-e "s|/usr/local/mysql|/opt/mariadb|g" \
-e "/WantedBy=multi-user.target/a Alias=mysql.service" \
/etc/systemd/system/mariadb.service
sed -i "s|/usr/local/mysql|/opt/mariadb|g" /opt/mariadb/bin/galera_recovery
启动服务
systemctl enable mariadb --now
systemctl status mariadb
登录
mysql -uroot -p
如果报错mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
yum install libncurses* -y
设置密码
alter user "root"@"localhost" identified by "YOUR_PASSWORD";
flush privileges;
网友评论