56 openEuler搭建Mariadb数据库服务器-安装、运行和卸载
56.1 安装
-
配置本地yum源,详细信息请参考《openEuler 22.03-LTS 搭建repo服务器》。
-
清除缓存。
# dnf clean all
例如示例命令如下:
[root@superman-21 ~]# dnf clean all 45 files removed [root@superman-21 ~]#
-
创建缓存。
# dnf makecache
例如示例命令如下:
[root@superman-21 ~]# dnf makecache OS 6.5 MB/s | 3.4 MB 00:00 everything 18 MB/s | 16 MB 00:00 EPOL 5.4 MB/s | 2.6 MB 00:00 debuginfo 3.2 MB/s | 3.9 MB 00:01 source 3.9 MB/s | 1.7 MB 00:00 update 15 MB/s | 29 MB 00:01 Metadata cache created. [root@superman-21 ~]#
-
在root权限下安装mariadb服务器。
# dnf install mariadb-server
例如示例命令如下:
[root@superman-21 ~]# dnf install mariadb-server Last metadata expiration check: 0:01:18 ago on 2022年12月19日 星期一 21时18分58秒. Dependencies resolved. ============================================================================================================================= Package Architecture Version Repository Size ============================================================================================================================= Installing: mariadb-server x86_64 4:10.5.16-1.oe2203 update 18 M Installing dependencies: mariadb x86_64 4:10.5.16-1.oe2203 update 6.0 M mariadb-common x86_64 4:10.5.16-1.oe2203 update 27 k mariadb-config x86_64 4:10.5.16-1.oe2203 update 8.0 k mariadb-errmsg x86_64 4:10.5.16-1.oe2203 update 231 k mysql-selinux noarch 1.0.0-2.oe2203 everything 35 k perl-DBD-MariaDB x86_64 1.21-3.oe2203 OS 122 k perl-DBI x86_64 1.643-3.oe2203 update 462 k Installing weak dependencies: mariadb-backup x86_64 4:10.5.16-1.oe2203 update 6.6 M mariadb-gssapi-server x86_64 4:10.5.16-1.oe2203 update 14 k mariadb-server-utils x86_64 4:10.5.16-1.oe2203 update 1.1 M Transaction Summary ============================================================================================================================= Install 11 Packages Total download size: 32 M Installed size: 168 M Is this ok [y/N]: y Downloading Packages: (1/11): mysql-selinux-1.0.0-2.oe2203.noarch.rpm 286 kB/s | 35 kB 00:00 (2/11): perl-DBD-MariaDB-1.21-3.oe2203.x86_64.rpm 617 kB/s | 122 kB 00:00 (3/11): mariadb-common-10.5.16-1.oe2203.x86_64.rpm 648 kB/s | 27 kB 00:00 (4/11): mariadb-config-10.5.16-1.oe2203.x86_64.rpm 205 kB/s | 8.0 kB 00:00 (5/11): mariadb-errmsg-10.5.16-1.oe2203.x86_64.rpm 2.7 MB/s | 231 kB 00:00 (6/11): mariadb-gssapi-server-10.5.16-1.oe2203.x86_64.rpm 328 kB/s | 14 kB 00:00 (7/11): mariadb-server-10.5.16-1.oe2203.x86_64.rpm 15 MB/s | 18 MB 00:01 (8/11): mariadb-server-utils-10.5.16-1.oe2203.x86_64.rpm 4.4 MB/s | 1.1 MB 00:00 (9/11): perl-DBI-1.643-3.oe2203.x86_64.rpm 8.9 MB/s | 462 kB 00:00 (10/11): mariadb-backup-10.5.16-1.oe2203.x86_64.rpm 2.9 MB/s | 6.6 MB 00:02 (11/11): mariadb-10.5.16-1.oe2203.x86_64.rpm 2.3 MB/s | 6.0 MB 00:02 ----------------------------------------------------------------------------------------------------------------------------- Total 12 MB/s | 32 MB 00:02 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: perl-DBI-1.643-3.oe2203.x86_64 1/11 Installing : perl-DBI-1.643-3.oe2203.x86_64 1/11 Running scriptlet: perl-DBI-1.643-3.oe2203.x86_64 1/11 Installing : mariadb-config-4:10.5.16-1.oe2203.x86_64 2/11 Installing : mariadb-common-4:10.5.16-1.oe2203.x86_64 3/11 Installing : mariadb-errmsg-4:10.5.16-1.oe2203.x86_64 4/11 Installing : perl-DBD-MariaDB-1.21-3.oe2203.x86_64 5/11 Running scriptlet: mysql-selinux-1.0.0-2.oe2203.noarch 6/11 Installing : mysql-selinux-1.0.0-2.oe2203.noarch 6/11 Running scriptlet: mysql-selinux-1.0.0-2.oe2203.noarch 6/11 libsemanage.semanage_direct_install_info: Overriding mysql module at lower priority 100 with module at priority 200. Installing : mariadb-4:10.5.16-1.oe2203.x86_64 7/11 Installing : mariadb-backup-4:10.5.16-1.oe2203.x86_64 8/11 Installing : mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64 9/11 Running scriptlet: mariadb-server-4:10.5.16-1.oe2203.x86_64 10/11 Installing : mariadb-server-4:10.5.16-1.oe2203.x86_64 10/11 Running scriptlet: mariadb-server-4:10.5.16-1.oe2203.x86_64 10/11 Installing : mariadb-server-utils-4:10.5.16-1.oe2203.x86_64 11/11 Running scriptlet: mysql-selinux-1.0.0-2.oe2203.noarch 11/11 Running scriptlet: mariadb-server-utils-4:10.5.16-1.oe2203.x86_64 11/11 /usr/lib/tmpfiles.d/pesign.conf:1: Line references path below legacy directory /var/run/, updating /var/run/pesign → /run/pesign; please update the tmpfiles.d/ drop-in file accordingly. Verifying : perl-DBD-MariaDB-1.21-3.oe2203.x86_64 1/11 Verifying : mysql-selinux-1.0.0-2.oe2203.noarch 2/11 Verifying : mariadb-4:10.5.16-1.oe2203.x86_64 3/11 Verifying : mariadb-backup-4:10.5.16-1.oe2203.x86_64 4/11 Verifying : mariadb-common-4:10.5.16-1.oe2203.x86_64 5/11 Verifying : mariadb-config-4:10.5.16-1.oe2203.x86_64 6/11 Verifying : mariadb-errmsg-4:10.5.16-1.oe2203.x86_64 7/11 Verifying : mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64 8/11 Verifying : mariadb-server-4:10.5.16-1.oe2203.x86_64 9/11 Verifying : mariadb-server-utils-4:10.5.16-1.oe2203.x86_64 10/11 Verifying : perl-DBI-1.643-3.oe2203.x86_64 11/11 Installed: mariadb-4:10.5.16-1.oe2203.x86_64 mariadb-backup-4:10.5.16-1.oe2203.x86_64 mariadb-common-4:10.5.16-1.oe2203.x86_64 mariadb-config-4:10.5.16-1.oe2203.x86_64 mariadb-errmsg-4:10.5.16-1.oe2203.x86_64 mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64 mariadb-server-4:10.5.16-1.oe2203.x86_64 mariadb-server-utils-4:10.5.16-1.oe2203.x86_64 mysql-selinux-1.0.0-2.oe2203.noarch perl-DBD-MariaDB-1.21-3.oe2203.x86_64 perl-DBI-1.643-3.oe2203.x86_64 Complete! [root@superman-21 ~]#
-
查看安装后的rpm包。
# rpm -qa | grep mariadb
例如示例命令如下:
[root@superman-21 ~]# rpm -qa | grep mariadb mariadb-errmsg-10.5.16-1.oe2203.x86_64 mariadb-common-10.5.16-1.oe2203.x86_64 mariadb-gssapi-server-10.5.16-1.oe2203.x86_64 mariadb-server-utils-10.5.16-1.oe2203.x86_64 mariadb-backup-10.5.16-1.oe2203.x86_64 mariadb-10.5.16-1.oe2203.x86_64 mariadb-server-10.5.16-1.oe2203.x86_64 mariadb-config-10.5.16-1.oe2203.x86_64 mariadb-connector-c-3.1.13-2.oe2203.x86_64 [root@superman-21 ~]#
56.2 运行
-
设置mariadb数据库配置文件。
/etc/my.cnf的[client-server]下添加socket,[mysqld]下添加datadir、log-error,pid-file、socket;
/etc/my.cnf.d/mariadb-server.cnf的[mysqld]下添加datadir、log-error,pid-file、socket
# vi /etc/my.cnf
例如示例命令如下:
[root@superman-21 ~]# cat /etc/my.cnf # # This group is read both both by the client and the server # use it for options that affect everything # [client-server] socket = /data/mariadb/tmp/mysql.sock # # This group is read by the server # [mysqld] datadir = /data/mariadb/data log-error = /data/mariadb/log/mariadberr.log pid-file = /data/mariadb/run/mariadb.pid socket = /data/mariadb/tmp/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # # include all files from the config directory # !includedir /etc/my.cnf.d [root@superman-21 ~]# [root@superman-21 ~]# cat /etc/my.cnf.d/mariadb-server.cnf # # These groups are read by MariaDB server. # Use it for options that only the server (but not clients) should see # # See the examples of server my.cnf files in /usr/share/mysql/ # # this is read by the standalone daemon and embedded servers [server] # this is only for the mysqld standalone daemon # 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 mysqld/mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld] datadir = /data/mariadb/data log-error = /data/mariadb/log/mariadberr.log pid-file = /data/mariadb/run/mariadb.pid socket = /data/mariadb/tmp/mysql.sock # # * Galera-related settings # [galera] # Mandatory settings #wsrep_on=ON #wsrep_provider= #wsrep_cluster_address= #binlog_format=row #default_storage_engine=InnoDB #innodb_autoinc_lock_mode=2 # # Allow server to accept connections on all interfaces. # #bind-address=0.0.0.0 # # Optional setting #wsrep_slave_threads=1 #innodb_flush_log_at_trx_commit=0 # this is only for embedded server [embedded] # This group is only read by MariaDB servers, not by MySQL. # If you use the same .cnf file for MySQL and MariaDB, # you can put MariaDB-only options here [mariadb] # This group is only read by MariaDB-10.5 servers. # If you use the same .cnf file for MariaDB of different versions, # use this group for options that older servers don't understand [mariadb-10.5] [root@superman-21 ~]#
-
在root权限下启动mariadb服务器。
# systemctl start mariadb
例如示例命令如下:
[root@superman-21 ~]# systemctl start mariadb.service [root@superman-21 ~]# [root@superman-21 ~]# ll /data/mariadb/data/ 总用量 122920 -rw-rw---- 1 mysql mysql 24576 12月 20 17:03 aria_log.00000001 -rw-rw---- 1 mysql mysql 52 12月 20 17:03 aria_log_control -rw-rw---- 1 mysql mysql 972 12月 20 17:03 ib_buffer_pool -rw-rw---- 1 mysql mysql 12582912 12月 20 17:03 ibdata1 -rw-rw---- 1 mysql mysql 100663296 12月 20 17:03 ib_logfile0 -rw-rw---- 1 mysql mysql 12582912 12月 20 17:03 ibtmp1 -rw-rw---- 1 mysql mysql 0 12月 20 17:03 multi-master.info drwx------ 2 mysql mysql 4096 12月 20 17:03 mysql -rw-rw---- 1 mysql mysql 16 12月 20 17:03 mysql_upgrade_info drwx------ 2 mysql mysql 20 12月 20 17:03 performance_schema [root@superman-21 ~]# [root@superman-21 ~]# ll /data/mariadb/log/ 总用量 4 -rw-rw---- 1 mysql mysql 1578 12月 20 17:03 mariadberr.log [root@superman-21 ~]# [root@superman-21 ~]# ll /data/mariadb/run/ 总用量 4 -rw-rw---- 1 mysql mysql 5 12月 20 17:03 mariadb.pid [root@superman-21 ~]# [root@superman-21 ~]# ll /data/mariadb/tmp/ 总用量 0 srwxrwxrwx 1 mysql mysql 0 12月 20 17:03 mysql.sock [root@superman-21 ~]#
-
设置socket软连接。
# ln -s /data/mariadb/tmp/mysql.sock /var/lib/mysql/mysql.sock
例如示例命令如下:
[root@superman-21 ~]# ln -s /data/mariadb/tmp/mysql.sock /var/lib/mysql/mysql.sock [root@superman-21 ~]#
-
在root权限下安全初始化数据库。
# /usr/bin/mysql_secure_installation
命令执行过程中需要输入数据库的root设置的密码,若没有密码则直接按“Enter”。然后根据提示及实际情况进行设置。
例如示例命令如下:
[root@superman-21 ~]# /usr/bin/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] n ... skipping. 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@superman-21 ~]#
-
登录数据库。
# mysql -u root -p
命令执行后提示输入密码。密码为4中设置的密码。
说明: 执行 \q 或者 exit 可退出数据库。
例如示例命令如下:
[root@superman-21 ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 11 Server version: 10.5.16-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)]> MariaDB [(none)]> \q Bye [root@superman-21 ~]# [root@superman-21 ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 12 Server version: 10.5.16-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)]> exit Bye [root@superman-21 ~]#
56.3 卸载
-
在root权限下关闭数据库进程。
# systemctl stop mariadb
例如示例命令如下:
[root@superman-21 ~]# systemctl stop mariadb [root@superman-21 ~]#
-
在root权限下执行dnf remove mariadb-server命令卸载mariadb。
# dnf remove mariadb-server
例如示例命令如下:
[root@superman-21 ~]# dnf remove mariadb-server Dependencies resolved. ============================================================================================================================= Package Architecture Version Repository Size ============================================================================================================================= Removing: mariadb-server x86_64 4:10.5.16-1.oe2203 @update 91 M Removing unused dependencies: mariadb x86_64 4:10.5.16-1.oe2203 @update 38 M mariadb-backup x86_64 4:10.5.16-1.oe2203 @update 27 M mariadb-common x86_64 4:10.5.16-1.oe2203 @update 179 k mariadb-config x86_64 4:10.5.16-1.oe2203 @update 345 mariadb-errmsg x86_64 4:10.5.16-1.oe2203 @update 2.6 M mariadb-gssapi-server x86_64 4:10.5.16-1.oe2203 @update 19 k mariadb-server-utils x86_64 4:10.5.16-1.oe2203 @update 7.3 M mysql-selinux noarch 1.0.0-2.oe2203 @everything 49 k perl-DBD-MariaDB x86_64 1.21-3.oe2203 @OS 356 k perl-DBI x86_64 1.643-3.oe2203 @update 1.6 M Transaction Summary ============================================================================================================================= Remove 11 Packages Freed space: 168 M Is this ok [y/N]: y Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64 1/1 Erasing : mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64 1/11 Erasing : mariadb-backup-4:10.5.16-1.oe2203.x86_64 2/11 Running scriptlet: mariadb-server-4:10.5.16-1.oe2203.x86_64 3/11 Erasing : mariadb-server-4:10.5.16-1.oe2203.x86_64 3/11 警告:/etc/my.cnf.d/mariadb-server.cnf 已另存为 /etc/my.cnf.d/mariadb-server.cnf.rpmsave Running scriptlet: mariadb-server-4:10.5.16-1.oe2203.x86_64 3/11 Erasing : mariadb-4:10.5.16-1.oe2203.x86_64 4/11 Erasing : mariadb-server-utils-4:10.5.16-1.oe2203.x86_64 5/11 Erasing : mariadb-errmsg-4:10.5.16-1.oe2203.x86_64 6/11 Erasing : mariadb-common-4:10.5.16-1.oe2203.x86_64 7/11 Erasing : mariadb-config-4:10.5.16-1.oe2203.x86_64 8/11 警告:/etc/my.cnf 已另存为 /etc/my.cnf.rpmsave Erasing : mysql-selinux-1.0.0-2.oe2203.noarch 9/11 Running scriptlet: mysql-selinux-1.0.0-2.oe2203.noarch 9/11 libsemanage.semanage_direct_remove_key: mysql module at priority 100 is now active. Erasing : perl-DBD-MariaDB-1.21-3.oe2203.x86_64 10/11 Running scriptlet: perl-DBI-1.643-3.oe2203.x86_64 11/11 Erasing : perl-DBI-1.643-3.oe2203.x86_64 11/11 Running scriptlet: perl-DBI-1.643-3.oe2203.x86_64 11/11 Verifying : mariadb-4:10.5.16-1.oe2203.x86_64 1/11 Verifying : mariadb-backup-4:10.5.16-1.oe2203.x86_64 2/11 Verifying : mariadb-common-4:10.5.16-1.oe2203.x86_64 3/11 Verifying : mariadb-config-4:10.5.16-1.oe2203.x86_64 4/11 Verifying : mariadb-errmsg-4:10.5.16-1.oe2203.x86_64 5/11 Verifying : mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64 6/11 Verifying : mariadb-server-4:10.5.16-1.oe2203.x86_64 7/11 Verifying : mariadb-server-utils-4:10.5.16-1.oe2203.x86_64 8/11 Verifying : mysql-selinux-1.0.0-2.oe2203.noarch 9/11 Verifying : perl-DBD-MariaDB-1.21-3.oe2203.x86_64 10/11 Verifying : perl-DBI-1.643-3.oe2203.x86_64 11/11 Removed: mariadb-4:10.5.16-1.oe2203.x86_64 mariadb-backup-4:10.5.16-1.oe2203.x86_64 mariadb-common-4:10.5.16-1.oe2203.x86_64 mariadb-config-4:10.5.16-1.oe2203.x86_64 mariadb-errmsg-4:10.5.16-1.oe2203.x86_64 mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64 mariadb-server-4:10.5.16-1.oe2203.x86_64 mariadb-server-utils-4:10.5.16-1.oe2203.x86_64 mysql-selinux-1.0.0-2.oe2203.noarch perl-DBD-MariaDB-1.21-3.oe2203.x86_64 perl-DBI-1.643-3.oe2203.x86_64 Complete! [root@superman-21 ~]#
标签:mariadb,10.5,x86,16,oe2203,56,64,openEuler,Mariadb From: https://blog.51cto.com/u_237826/6207265