Linux-mariadb-10.4-二进制安装
安装环境
系统环境centos8
下载Mariadb 二进制编码安装包
[root@centos8-liyj ~]#wget https://mirrors.aliyun.com/mariadb//mariadb-10.4.24/bintar-linux-glibc_214-x86_64/mariadb-10.4.24-linux-glibc_214-x86_64.tar.gz
--2022-05-12 11:21:26-- https://mirrors.aliyun.com/mariadb//mariadb-10.4.24/bintar-linux-glibc_214-x86_64/mariadb-10.4.24-linux-glibc_214-x86_64.tar.gz Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 223.113.144.241, 223.113.144.248, 223.113.144.238, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|223.113.144.241|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1156844354 (1.1G) [application/octet-stream] Saving to: ‘mariadb-10.4.24-linux-glibc_214-x86_64.tar.gz’ mariadb-10.4.24-linux-glibc_ 100%[==============================================>] 1.08G 1.81MB/s in 10m 41s 2022-05-12 11:32:07 (1.72 MB/s) - ‘mariadb-10.4.24-linux-glibc_214-x86_64.tar.gz’ saved [1156844354/1156844354]
安装相关包
[root@centos8-liyj ~]#yum -y install libaio numactl-libs
用户和组
[root@centos8-liyj ~]#groupadd mysql [root@centos8-liyj ~]#useradd -r -g mysql -s /bin/false mysql
创建目录和授权
[root@centos8-liyj ~]#mkdir -p /data/mysql/{data,logs,tmp} [root@centos8-liyj ~]#chown -R mysql.mysql /data/mysql [root@centos8-liyj ~]#chmod -R 770 /data/mysql [root@centos8-liyj ~]#tree /data /data └── mysql #binlog文件存储位置 ├── data #数据文件存储位置 ├── logs #日志问价能存储位置 └── tmp #缓存目录位置 4 directories, 0 files
准备程序文件
[root@centos8-liyj ~]#tar xf mariadb-10.4.24-linux-glibc_214-x86_64_.tar.gz -C /usr/local [root@centos8-liyj ~]#cd /usr/local/ [root@centos8-liyj /usr/local]#ln -s mariadb-10.4.24-linux-glibc_214-x86_64/ mysql [root@centos8-liyj /usr/local]#chown -R root.root /usr/local/mysql/ [root@centos8-liyj /usr/local]#ll total 0 drwxr-xr-x. 2 root root 6 Jun 22 2021 bin drwxr-xr-x. 2 root root 6 Jun 22 2021 etc drwxr-xr-x. 2 root root 6 Jun 22 2021 games drwxr-xr-x. 2 root root 6 Jun 22 2021 include drwxr-xr-x. 2 root root 6 Jun 22 2021 lib drwxr-xr-x. 3 root root 17 Jun 22 2021 lib64 drwxr-xr-x. 2 root root 6 Jun 22 2021 libexec drwxrwxr-x 12 root root 257 Feb 12 07:33 mariadb-10.4.24-linux-glibc_214-x86_64 lrwxrwxrwx 1 root root 39 May 12 14:25 mysql -> mariadb-10.4.24-linux-glibc_214-x86_64/ drwxr-xr-x. 2 root root 6 Jun 22 2021 sbin drwxr-xr-x. 5 root root 49 Jun 22 2021 share drwxr-xr-x. 2 root root 6 Jun 22 2021 src
主备配置文件
[root@centos8-liyj /usr/local]#cd mysql/support-files/ [root@centos8-liyj /usr/local/mysql/support-files]#ll total 36 -rwxr-xr-x 1 root root 1153 Feb 11 03:48 binary-configure -rw-r--r-- 1 root root 1328 Feb 11 03:42 magic -rwxr-xr-x 1 root root 1564 Feb 11 03:48 mysqld_multi.server -rwxr-xr-x 1 root root 942 Feb 11 03:48 mysql-log-rotate -rwxr-xr-x 1 root root 12228 Feb 11 03:48 mysql.server drwxr-xr-x 4 root root 37 Feb 11 04:33 policy -rw-r--r-- 1 root root 3474 Feb 11 03:48 wsrep.cnf -rwxr-xr-x 1 root root 2230 Feb 11 03:48 wsrep_notify [root@centos8-liyj /usr/local/mysql/support-files]#cp wsrep.cnf /etc/my.cnf
[root@centos8-liyj ~]#vim /etc/my.cnf
[mysqld]
datadir = /data/mysql/data
pid-file = /data/mysql/mysqll.pid
relay_log = /data/mysql/logs/mysql_relay.log
[client]
socket = /tmp/mysql.sock
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
# This file contains wsrep-related mysqld options. It should be included # in the main MySQL configuration file. # # Options that need to be customized: # - wsrep_provider # - wsrep_cluster_address # - wsrep_sst_auth # The rest of defaults should work out of the box. ## ## mysqld options _MANDATORY_ for correct opration of the cluster ## [mysqld] datadir = /data/mysql/data pid-file = /data/mysql/mysqll.pid server-id = 50 relay_log = /data/mysql/logs/mysql_relay.log [client] socket = /tmp/mysql.sock
准备环境变量
[root@centos8-liyj /usr/local]#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@centos8-liyj /usr/local]#. /etc/profile.d/mysql.sh
初始化数据库
[root@centos8-liyj ~]#cd /usr/local/mysql/ [root@centos8-liyj /usr/local/mysql]#scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
Installing MariaDB/MySQL system tables in '/data/mysql/data' ... 2022-05-12 14:31:31 0 [Warning] You need to use --log-bin to make --binlog-format work. OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system Two all-privilege accounts were created. One is root@localhost, it has no password, but you need to be system 'root' user to connect. Use, for example, sudo mysql The second is mysql@localhost, it has no password either, but you need to be the system 'mysql' user to connect. After connecting you can set the password, if you would need to be able to connect as any of these users with a password and without sudo See the MariaDB Knowledgebase at http://mariadb.com/kb You can start the MariaDB daemon with: cd '/usr/local/mysql' ; /usr/local/mysql/bin/mysqld_safe --datadir='/data/mysql/data' You can test the MariaDB daemon with mysql-test-run.pl cd '/usr/local/mysql/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/. Consider joining MariaDB's strong and vibrant community: https://mariadb.org/get-involved/
准备服务脚本和启动
[root@centos8-liyj ~]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@centos8-liyj ~]#chkconfig --add mysqld [root@centos8-liyj ~]#systemctl start mysqld Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
mariadb数据库安装完成后,要安全初始化后才能登录
[root@centos8-liyj ~]#cd /usr/local/mysql/support-files/ [root@centos8-liyj /usr/local/mysql/support-files]#mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): 当前数据库管理员的密码,无密码直接回 OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] y 切换到unix_套接字身份验证 Enabled successfully! Reloading privilege tables.. ... Success! You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] y 设定数据管理员密码 New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y 移除匿名用户登录 ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y 移除管理原远程登录 ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y 移除测试库 - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y 刷新数据库 ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
登录测试
[root@centos8-liyj ~]#mysql -uroot -patech123456 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 19 Server version: 10.4.24-MariaDB 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)]>