MySQL入門——在Linux下安裝和卸載MariaDB


MySQL入門——在Linux下安裝和卸載MariaDB

摘要:本文主要學習了如何在Linux系統中安裝和卸載MariaDB數據庫。

查看有沒有安裝過MariaDB

使用命令查看有沒有安裝過:

1 [root@localhost ~]# yum list installed | grep mariadb
2 mariadb-libs.x86_64                   1:5.5.44-2.el7.centos            @anaconda
3 [root@localhost ~]# 

使用的系統是CentOS版本是7.2.1511,可以看到系統只是安裝了用到的libs包,並沒有安裝MariaDB的服務端和客戶端。

安裝MariaDB

安裝

使用命令安裝:

 1 [root@localhost ~]# yum install -y mariadb mariadb-server
 2 已加載插件:fastestmirror
 3 Loading mirror speeds from cached hostfile
 4  * base: mirrors.huaweicloud.com
 5  * extras: mirrors.huaweicloud.com
 6  * updates: mirrors.huaweicloud.com
 7 正在解決依賴關系
 8 --> 正在檢查事務
 9 ...
10 完畢!
11 [root@localhost ~]#

使用命令查看安裝的程序:

1 [root@localhost ~]# yum list installed | grep mariadb
2 mariadb.x86_64                        1:5.5.60-1.el7_5                 @base    
3 mariadb-libs.x86_64                   1:5.5.60-1.el7_5                 @base    
4 mariadb-server.x86_64                 1:5.5.60-1.el7_5                 @base    
5 [root@localhost ~]# 

啟動服務

查看MariaDB的狀態:

1 [root@localhost ~]# systemctl status mariadb
2 ● mariadb.service - MariaDB database server
3    Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
4    Active: inactive (dead)
5 [root@localhost ~]#

啟動MariaDB並查看MariaDB的狀態:

 1 [root@localhost ~]# systemctl start mariadb
 2 [root@localhost ~]# systemctl status mariadb
 3 ● mariadb.service - MariaDB database server
 4    Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
 5    Active: active (running) since 六 2019-07-13 05:19:08 CST; 36s ago
 6   Process: 4162 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
 7   Process: 4082 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 8  Main PID: 4161 (mysqld_safe)
 9    CGroup: /system.slice/mariadb.service
10            ├─4161 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
11            └─4323 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socke...
12 ...
13 [root@localhost ~]#

連接數據庫

連接並查看版本:

 1 [root@localhost ~]# mysql -uroot
 2 Welcome to the MariaDB monitor.  Commands end with ; or \g.
 3 Your MariaDB connection id is 2
 4 Server version: 5.5.60-MariaDB MariaDB Server
 5 
 6 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
 7 
 8 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 9 
10 MariaDB [(none)]> select version();
11 +----------------+
12 | version()      |
13 +----------------+
14 | 5.5.60-MariaDB |
15 +----------------+
16 1 row in set (0.00 sec)
17 
18 MariaDB [(none)]>

退出:

1 MariaDB [(none)]> exit
2 Bye
3 [root@localhost ~]#

簡單配置

使用命令對MariaDB進行簡單配置:

1 [root@localhost ~]# mysql_secure_installation
2 
3 NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
4       SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

輸入當前的密碼,如果沒有設置就回車:

1 In order to log into MariaDB to secure it, we'll need the current
2 password for the root user.  If you've just installed MariaDB, and
3 you haven't set the root password yet, the password will be blank,
4 so you should just press enter here.
5 
6 Enter current password for root (enter for none): 
7 OK, successfully used password, moving on...

是否為root用戶設置密碼:

1 Setting the root password ensures that nobody can log into the MariaDB
2 root user without the proper authorisation.
3 
4 Set root password? [Y/n] Y
5 New password: 
6 Re-enter new password: 
7 Password updated successfully!
8 Reloading privilege tables..
9  ... Success!

是否刪除匿名用戶:

1 By default, a MariaDB installation has an anonymous user, allowing anyone
2 to log into MariaDB without having to have a user account created for
3 them.  This is intended only for testing, and to make the installation
4 go a bit smoother.  You should remove them before moving into a
5 production environment.
6 
7 Remove anonymous users? [Y/n] 
8  ... Success!

是否允許root用戶遠程登錄:

1 Normally, root should only be allowed to connect from 'localhost'.  This
2 ensures that someone cannot guess at the root password from the network.
3 
4 Disallow root login remotely? [Y/n] 
5  ... Success!

是否刪除test數據庫:

1 By default, MariaDB comes with a database named 'test' that anyone can
2 access.  This is also intended only for testing, and should be removed
3 before moving into a production environment.
4 
5 Remove test database and access to it? [Y/n] 
6  - Dropping test database...
7  ... Success!
8  - Removing privileges on test database...
9  ... Success!

是否重新加載權限表:

1 Reloading the privilege tables will ensure that all changes made so far
2 will take effect immediately.
3 
4 Reload privilege tables now? [Y/n] 
5  ... Success!

設置完成:

1 Cleaning up...
2 
3 All done!  If you've completed all of the above steps, your MariaDB
4 installation should now be secure.
5 
6 Thanks for using MariaDB!
7 [root@localhost ~]# 

卸載MariaDB

使用命令卸載安裝包:

1 [root@localhost ~]# yum remove -y mariadb-libs
2 已加載插件:fastestmirror
3 正在解決依賴關系
4 --> 正在檢查事務
5 ...
6 完畢!
7 [root@localhost ~]# 

查看卸載后的安裝情況:

1 [root@localhost ~]# yum list installed | grep mariadb
2 [root@localhost ~]# 

表明已經從系統中卸載了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM