MySQL 数据库新项目自打被Oracle 企业收购以后,从开源项目变化变成了“闭源”手机软件,这造成 IT 领域中的许多公司及其生产商陆续挑选采用了数据库手机软件的后来居上 — MariaDB 数据库管理系统。MariaDB 数据库管理系统也因而迅速占领了销售市场。
此章将详细介绍数据库及其数据库管理系统的基础知识,随后再详细介绍 MariaDB 数据库管理系统的內容,最终将根据亲手试验的方法,协助诸位读者把握 MariaDB 数据库管理系统的一些基本实际操作。例如,帐户的创立与管理方法、帐户管理权限的受权;新创建数据库、新建数据库表格;对数据库实行新创建、删掉、改动和查找等实际操作。此章最终还详细介绍了数据库的备份与还原方式。
在学好此章內容以后,读者不仅可以担任工作环境中的数据库管理方面,还能够把握RHCE 考試中数据库管理方法主题风格有关的內容。
数据库就是指依照一些特殊构造来储存统计数据的数据库管理。在现如今这一互联网大数据技术快速兴起的时代,互联网技术上每日都是会转化成大量的数据信息信息,数据库技术也从最开始只有储存简单的表格数据信息的单一集中化储存方式,发展趋势到了现如今储存海量信息的大中型分布式系统方式。在信息化社会发展中,可以全面合理地监管和运用各种各样数据信息,发掘当中的使用价值,是开展科研与管理决策管理方法的主要前提条件。与此同时,数据库技术也是管理方法信息系统软件、办公系统系统软件、信息处理系统等各种信息系统软件的关键构成部分,是开展研究和决定管理方法的关键技术方式。
数据库管理系统是一种可以对数据库中放置的信息开展创建、改动、删掉、搜索、维护保养等使用的软件系统。 它根据把电子计算机中主要的物理学数据交换成合适客户了解的抽象化逻辑性数据信息,合理地减少数据库管理方法的技术门坎,因而就算是从业 Linux 运维管理工作中的技术工程师还可以对数据库开展基础的监管实际操作。可是,必须提示诸位读者,这书的技术主线任务仍然是 Linux系统软件的运维管理,而数据库管理系统只不过在这里主线任务上的一个內容持续横着拓展、竖向加重的支系,不可以期望在一两天以内就可以熟练数据库管理方法技术。如果有读者在学好此章內容以后对数据库管理方法技术造成了浓厚兴趣,并期待谋得一份相应的工作中,那麼就必须附加给自己订制一个学习计划了。
即然是解读数据库管理方法技术,就一定绕不动 MySQL。MySQL 是一款市场份额十分高的数据库管理系统,技术完善、配备流程相对性简易,并且有着较好的扩展性。可是,因为Oracle 企业在 2009 年回收了 MySQL 的总公司 Sun,因而 MySQL 数据库新项目也随着列入Oracle 手下, 逐渐发展为维持着开源项目的真实身份, 但又办理了多种商业服务专利权的系统软件。 开源项目是全世界网络黑客、极克、程序猿等技术大神在开源项目的大集团旗下的公共性智慧结晶,自身的劳动所得被别的企业商业化的当然也伤了一大批开源系统工作人员的心,因而由 MySQL 新项目创始人再次产品研发了一款名叫 MariaDB 的全新升级数据库管理系统。此软件现阶段由开源项目开展维护保养,是MySQL 的支系商品,并且几乎彻底兼容 MySQL。
此外,因为各大企业中间普遍存在着竞争关系或利益关系,另加 MySQL 在被回收以后慢慢由开源系统向闭源手机软件变化,许多企业抛下了 MySQL。现阶段,Google、 ** 等技术行业决策将 MySQL 数据库上的项目迁移到 MariaDB 数据库,Linux 开源网站的领导者redhat企业也选择在 RHEL 7、 CentOS 7 及其全新的 Fedora 系统软件中, 将 MariaDB 做为默认设置的数据库管理系统,并且redhat企业也是初次将数据库专业知识添加到了 RHCE 验证的考试试题中。接着,也有数十个普遍的 Linux 系统软件(如 openSUSE、Slackware 等)也做出了一样的表态发言。
可是,挑明而言,尽管 IT 领域大佬都决策选用 MariaDB 数据库管系统软件,这并不代表着MariaDB 较之于 MySQL 有显著的优点。刘遄教师用了近半个月的時间检测了 MariaDB 与MySQL 的差别,并开展了多种性能指标,并没发觉新闻媒体常说的那类显著的优点。可以说,MariaDB 和 MySQL 在功能上基本上保持一致,二者的系统命令也十分相似。从实干的方面而言,在了解了 MariaDB 数据库的指令和操作过程以后,在今后的工作即使碰到 MySQL 数据库,还可以迅速入门。因此,这两个数据库系统软件无论选取哪一个来学习培训都悉听君便,而这书往往挑选以 MariaDB 数据库开展解读,关键是以 RHCE 认证考试和技术垄断性的视角作的决策。
相比于 MySQL, MariaDB 数据库管理系统拥有许多新颖的拓展特点, 例如对微秒等级的适用、 线程池、 子查询提升、 过程汇报等。 在配备稳妥 Yum 软件仓库后, 就可以安裝布署 MariaDB数据库子程序及服务器端程序流程了。
# yum install ** riadb ** riadb-server
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos,
: subscription- ** nager
………………省去一部分輸出信息………………
Installing:
** riadb x86_ ** 1:5.5.60-1.el7_5 base 8.9 M
** riadb-server x86_ ** 1:5.5.60-1.el7_5 base 11 M
Installing for dependencies:
perl-Compress-Raw-Bzip2 x86_ ** 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_ ** 1:2.061-4.el7 base 57 k
perl-DBD-MySQL x86_ ** 4.023-6.el7 base 140 k
perl-DBI x86_ ** 1.627-4.el7 base 802 k
perl-Data-Dumper x86_ ** 2.145-3.el7 base 47 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k
Transaction Sum ** ry
====================================================================
Install 2 Packages ( 8 Dependent packages)
Total download size: 21 M
Installed size: 110 M
Is this ok [y/d/N]: y
Downloading packages:
Total 700 kB/s | 21 MB 00:30
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
………………省去一部分輸出信息………………
Installed:
** riadb.x86_ ** 1:5.5.60-1.el7_5 ** riadb-server.x86_ ** 1:5.5.60-1.el7_5
Dependency Installed:
perl-Compress-Raw-Bzip2.x86_ ** 0:2.061-3.el7
perl-Compress-Raw-Zlib.x86_ ** 1:2.061-4.el7
perl-DBD-MySQL.x86_ ** 0:4.023-6.el7
perl-DBI.x86_ ** 0:1.627-4.el7
perl-Data-Dumper.x86_ ** 0:2.145-3.el7
perl-IO-Compress.noarch 0:2.061-2.el7
perl-Net-Daemon.noarch 0:0.48-5.el7
perl-PlRPC.noarch 0:0.2020-14.el7
Complete!
# systemctl start ** riadb
# systemctl enable ** riadb
Created symlink from /etc/systemd/system/multi-user.target.wants/ ** riadb.service to /usr/lib/systemd/system/ ** riadb.service.
在确定 MariaDB 数据库手机软件软件安装结束并顺利运行后请不要马上应用。为了更好地保证数据库的安全系数和正常的运行, 必须先向数据库程序流程开展复位实际操作。 这一复位实际操作涉及到下边 5 个流程。
➢ 设定 root 管理人员在数据库中的登陆密码值(留意,该登陆密码并不是 root 管理人员在系统软件中的登陆密码,这儿的登陆密码值默认设置应当为空,可同时按空格键) 。
➢ 设定 root 管理人员在数据库中的专用登陆密码。
➢ 接着删掉密名帐户,并应用 root 管理人员从远程登陆数据库,以保证数据库上运转的销售业务的安全系数。
➢ 删掉默认设置的检测数据库,撤销检测数据库的一系列访问限制。
➢ 更新受权目录,让复位的设置马上起效。
针对以上数据库复位的操作流程,早已在下面的輸出信息边上开展了简易注解,保证诸位读者更直接地掌握要导入的內容:
# 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, well need the current
password for the root user. If youve just installed MariaDB, and
you havent set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):(当前数据库密码为空,直接按回车键)
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:(设置要为root管理设置的当前数据密码)
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 ** ke the installation
go a bit ** oother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y(删除匿名用户)
... Success!
Nor ** lly, 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(禁止root管理员从远程登录)
... 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(删除test数据库并取消对它的访问权限)
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes ** de so far
will take effect immediately.
Reload privilege tables now? [Y/n] y(刷新授权表,让初始化后的设定立即生效)
... Success!
Cleaning up...
All done! If youve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
在很多生产环境中都需要使用站库分离的技术(即网站和数据库不在同一个服务器上) ,如果需要让 root 管理员远程访问数据库,可在上面的初始化操作中设置策略,以允许 root 管理员从远程访问。然后还需要设置防火墙,使其放行对数据库服务程序的访问请求,数据库服务程序默认会占用 3306 端口,在防火墙策略中服务名称统一叫作 mysql:
# firewall-cmd --per ** nent --add-service=mysql
success
# firewall-cmd --reload
success
一切准备就绪。现在我们将首次登录 MariaDB 数据库。其中,-u 参数用来指定以 root 管理员的身份登录,而-p 参数用来验证该用户在数据库中的密码值。
# mysql -u root -p
Enter password: (此处输入root管理员在数据库中的密码)
Welcome to the MariaDB monitor. Com ** nds end with ; or g.
Your MariaDB connection id is 5
Server version: 5.5.35-MariaDB MariaDB Server
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type help; or h for help. Type c to clear the current input statement.
MariaDB [(none)]>
在登录 MariaDB 数据库后执行数据库命令时,都需要在命令后面用分号(;)结尾,这也是与 Linux 命令最显著的区别。大家需要慢慢习惯数据库命令的这种设定。下面执行如下命令查看数据库管理系统中当前都有哪些数据库:
MariaDB [(none)]> SHOW databases;
+--------------------+
| Database |
+--------------------+
| infor ** tion_sche ** |
| mysql |
| perfor ** nce_sche ** |
+--------------------+
3 rows in set (0.01 sec)
小试牛刀过后,接下来使用数据库命令将 root 管理员在数据库管理系统中的密码值修改为 linuxprobe。这样退出后再尝试登录,如果还坚持输入原先的密码,则将提示访问失败。
MariaDB [(none)]> SET password = PASSWORD(linuxprobe);
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
[root@linuxprobe ~]# mysql -u root -p
Enter password: root
ERROR 1045 (28000): Access denied for user root@localhost (using password: YES)
在生产环境中总不能一直“死啃”root 管理员。为了保障数据库系统的安全性,以及让其他用户协同管理数据库,我们可以在 MariaDB 数据库管理系统中为他们创建多个专用的数据库管理账户,然后再分配合理的权限,以满足他们的工作需求。为此,可使用 root 管理员登录数据库管理系统,然后按照“CREATE USER 用户名@主机名 IDENTIFIED BY 密码; ”的格式创建数据库管理账户。再次提醒大家,一定不要忘记每条数据库命令后面的分号(;) 。
MariaDB [(none)]> CREATE USER luke@localhost IDENTIFIED BY linuxprobe;
Query OK, 0 rows affected (0.00 sec)
创建的账户信息可以使用 select 命令语句来查询。下面命令查询的是账户 luke 的主机名称、账户名称以及经过加密的密码值信息:
MariaDB [(none)]> use mysql
Reading table infor ** tion for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> SELECT HOST,USER,PASSWORD FROM user WHERE USER="luke";
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | luke | *55D9962586BE75F4B7D421E6655973DB07D6869F |
+-----------+------+-------------------------------------------+
不过,用户 luke 仅仅是一个普通账户,没有数据库的任何操作权限。不信的话,可以切换到 luke 账户来查询数据库管理系统中当前都有哪些数据库。可以发现,该账户甚至没法查看完整的数据库列表(刚才使用 root 账户时可以查看到 3 个数据库列表) :
MariaDB [mysql]> exit
Bye
# mysql -u luke -p
Enter password: (此处输入luke帐户的数据库密码)
Welcome to the MariaDB monitor. Com ** nds end with ; or g.
Your MariaDB connection id is 6
Server version: 5.5.35-MariaDB MariaDB Server
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type help; or h for help. Type c to clear the current input statement.
MariaDB [(none)]> SHOW databases;
+--------------------+
| Database |
+--------------------+
| infor ** tion_sche ** |
+--------------------+
1 row in set (0.03 sec)
数据库管理系统所使用的命令一般都比较复杂。我们以 grant 命令为例进行说明。grant命令用于为账户进行授权,其常见格式如表 18-1 所示。在使用 grant 命令时需要写上要赋予的权限、数据库及表单名称,以及对应的账户及主机信息。其实,只要理解了命令中每个字段的功能含义,也就不觉得命令复杂难懂了。
GRANT 命令的常见格式以及解释
命令 作用
GRANT权限ON数据库.表单名称TO账户名@主机名 对某个特定数据库中的特定表单给予授权
GRANT 权限 ON 数据库.*TO 账户名@主机名 对某个特定数据库中的所有表单给予授权
GRANT 权限 ON*.*TO 账户名@主机名 对所有数据库及所有表单给予授权
GRANT权限1,权限2 ON 数据库.*TO账户名@主机名 对某个数据库中的所有表单给予多个授权
GRANT ALL PRIVILEGES ON *.*TO账户名@主机名 对所有数据库及所有表单给予全部授权(需 谨慎操作)
当然,账户的授权工作肯定是需要数据库管理员来执行的。下面以 root 管理员的身份登录到数据库管理系统中,针对 mysql 数据库中的 user 表单向账户 luke 授予查询、更新、删除以及插入等权限。
# mysql -u root –p
Enter password: (只处输入root管理员在数据库中的密码)
MariaDB [(none)]> use mysql;
Reading table infor ** tion for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> GRANT SELECT,UPDATE,DELETE,INSERT ON mysql.user TO luke@localhost;
Query OK, 0 rows affected (0.00 sec)
在执行完上述授权操作之后,我们再查看一下账户 luke 的权限:
MariaDB [(none)]> SHOW GRANTS FOR luke@localhost;
+-----------------------------------------------------------------------------+
| Grants for luke@localhost |
+-----------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO luke@localhost IDENTIFIED BY PASSWORD *55D9962586
BE75F4B7D421E6655973DB07D6869F |
| GRANT SELECT, INSERT, UPDATE, DELETE ON `mysql`.`user` TO luke@localhost |
+-----------------------------------------------------------------------------+
2 rows in set (0.00 sec)
上面输出信息中显示账户 luke 已经拥有了针对 mysql 数据库中 user 表单的一系列权限了。这时我们再切换到账户 luke,此时就能够看到 mysql 数据库了,而且还能看到表单 user(其余表单会因无权限而被继续隐藏) :
# mysql -u luke –p
Enter password: (此处输入luke用户在数据库中的密码)
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| infor ** tion_sche ** |
| mysql |
+--------------------+
2 rows in set (0.01 sec)
MariaDB [(none)]> use mysql
Reading table infor ** tion for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> SHOW TABLES;
+-----------------+
| Tables_in_mysql |
+-----------------+
| user |
+-----------------+
1 row in set (0.01 sec)
MariaDB [mysql]> exit
Bye
大家不要心急,我们接下来会慢慢学习数据库内容的修改方法。当前,先切换回 root 账户,移除刚才的授权。
# mysql -u root -p
Enter password: root
MariaDB [(none)]> use mysql;
Reading table infor ** tion for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [(none)]> REVOKE SELECT,UPDATE,DELETE,INSERT ON mysql.user FROM luke@
localhost;
Query OK, 0 rows affected (0.00 sec)
可以看到,除了移除授权的命令(revoke)与授权命令(grant)不同之外,其余部分都是一致的。这不仅好记而且也容易理解。执行移除授权命令后,再来查看账户 luke 的信息:
MariaDB [(none)]>SHOW GRANTS FOR luke@localhost;
+-----------------------------------------------------------------------------+
| Grants for luke@localhost |
+-----------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO luke@localhost IDENTIFIED BY PASSWORD *55D9962586
BE75F4B7D421E6655973DB07D6869F |
+-----------------------------------------------------------------------------+
1 row in set (0.00 sec)
在 MariaDB 数据库管理系统中,一个数据库可以存放多个数据表,数据表单是数据库中最重要最核心的内容。我们可以根据自己的需求自定义数据库表结构,然后在其中合理地存放数据,以便后期轻松地维护和修改。下表罗列了后文中将使用到的数据库命令以及对应的作用。
用于创建数据库的命令以及作用
命令 作用
CREATE DATABASE 数据库名称 创建新的数据库
DESCRIBE 表单名称 描述表单
UPDATE 表单名称 SET attribute=新值 WHERE attribute>原始值 更新表单中的数据
USE 数据库名称 指定使用的数据库
SHOW databases 显示当前已有的数据库
SHOW tables 显示当前数据库中的表单
SELECT * FROM 表单名称 从表单中选中某个记录值
DELETE FROM 表单名 WHERE attribute=值 从表单中删除某个记录值
建立数据库是管理数据的起点。现在尝试创建一个名为 linuxprobe 的数据库,然后再查看数据库列表,此时就能看到它了:
MariaDB [(none)]> CREATE DATABASE linuxprobe;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> SHOW databases;
+--------------------+
| Database |
+--------------------+
| infor ** tion_sche ** |
| linuxprobe |
| mysql |
| perfor ** nce_sche ** |
+--------------------+
4 rows in set (0.04 sec)
要想创建数据表单, 需要先切换到某个指定的数据库中。 比如在新建的 linuxprobe 数据库中创建表单 mybook,然后进行表单的初始化,即定义存储数据内容的结构。我们分别定义 3 个字段项,其中,长度为 15 个字符的字符型字段 name 用来存放图书名称,整型字段price 和 pages 分别存储图书的价格和页数。当执行完下述命令之后,就可以看到表单的结构信息了:
MariaDB [(none)]> use linuxprobe;
Database changed
MariaDB [linuxprobe]> CREATE TABLE mybook (name char(15),price int,pages int);
Query OK, 0 rows affected (0.16 sec)
MariaDB [linuxprobe]> DESCRIBE mybook;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| name | char(15) | YES | | NULL | |
| price | int(11) | YES | | NULL | |
| pages | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.02 sec)
接下来向 mybook 数据表单中插一条图书信息。为此需要使用 INSERT 命令,并在命令中写清表单名称以及对应的字段项。执行该命令之后即可完成图书写入信息。下面我们使用该命令插入一条图书信息,其中书名为 linuxprobe,价格和页数分别是 60 元和 518 页。在命令执行后也就意味着图书信息已经成功写入到数据表单中, 然后就可以查询表单中的内容了。我们在使用 select 命令查询表单内容时, 需要加上想要查询的字段; 如果想查看表单中的所有内容,则可以使用星号(*)通配符来显示:
MariaDB [linuxprobe]> INSERT INTO mybook(name,price,pages) VALUES(linuxprobe,
60, 518);
Query OK, 1 row affected (0.00 sec)
MariaDB [linuxprobe]> SELECT * FROM mybook;
+------------+-------+-------+
| name | price | pages |
+------------+-------+-------+
| linuxprobe | 60 | 518 |
+------------+-------+-------+
1 rows in set (0.01 sec)
对数据库运维人员来讲,需要做好四门功课 — 增、删、改、查。这意味着创建数据表单并在其中插入内容仅仅是第一步,还需要掌握数据表单内容的修改方法。例如,我们可以使用 update 命令将刚才插入的 linuxprobe 图书信息的价格修改为 55 元,然后在使用 select 命令查看该图书的名称和定价信息。 注意, 因为这里只查看图书的名称和定价, 而不涉及页码,所以无须再用星号通配符来显示所有内容。
MariaDB [linuxprobe]> UPDATE mybook SET price=55 ;
Query OK, 1 row affected (0.00 sec)
Rows ** tched: 1 Changed: 1 Warnings: 0
MariaDB [linuxprobe]> SELECT name,price FROM mybook;
+------------+-------+
| name | price |
+------------+-------+
| linuxprobe | 55 |
+------------+-------+
1 row in set (0.00 sec)
我们还可以使用 delete 命令删除某个数据表单中的内容。下面我们使用 delete 命令删除数据表单 mybook 中的所有内容,然后再查看该表单中的内容,可以发现该表单内容为空了。
MariaDB [linuxprobe]> DELETE FROM mybook;
Query OK, 1 row affected (0.01 sec)
MariaDB [linuxprobe]> SELECT * FROM mybook;
Empty set (0.00 sec)
一般来讲,数据表单中会存放成千上万条数据信息。比如我们刚刚创建的用于保存图书信息的 mybook 表单,随着时间的推移,里面的图书信息也会越来越多。在这样的情况下,如果我们只想查看其价格大于某个数值的图书时,又该如何定义查询语句呢?
下面先使用 insert 插入命令依次插入 4 条图书信息:
MariaDB [linuxprobe]> INSERT INTO mybook(name,price,pages) VALUES(linuxprobe1,
30, 518);
Query OK, 1 row affected (0.05 sec)
MariaDB [linuxprobe]> INSERT INTO mybook(name,price,pages) VALUES(linuxprobe2,
50, 518);
Query OK, 1 row affected (0.05 sec)
MariaDB [linuxprobe]> INSERT INTO mybook(name,price,pages) VALUES(linuxprobe3,
80, 518);
Query OK, 1 row affected (0.01 sec)
MariaDB [linuxprobe]> INSERT INTO mybook(name,price,pages) VALUES(linuxprobe4,
100, 518);
Query OK, 1 row affected (0.00 sec)
要想让查询结果更加精准,就需要结合使用 select 与 where 命令了。其中,where 命令是在数据库中进行匹配查询的条件命令。通过设置查询条件,就可以仅查找出符合该条件的数据。下表列出了 where 命令中常用的查询参数以及作用。
where 命令中使用的参数以及作用
参数 作用
= 相等
或!= 不相等
> 大于
= 大于或等于
SELECT * FROM mybook WHERE price>75;
+-------------+-------+-------+
| name | price | pages |
+-------------+-------+-------+
| linuxprobe3 | 80 | 518 |
| linuxprobe4 | 100 | 518 |
+-------------+-------+-------+
2 rows in set (0.06 sec)
MariaDB [linuxprobe]> SELECT * FROM mybook WHERE price!=80;
+-------------+-------+-------+
| name | price | pages |
+-------------+-------+-------+
| linuxprobe1 | 30 | 518 |
| linuxprobe2 | 50 | 518 |
| linuxprobe4 | 100 | 518 |
+-------------+-------+-------+
3 rows in set (0.01 sec)
MariaDB [mysql]> exit
Bye
mysqldump 命令用于备份数据库数据,格式为“mysqldump [参数] [数据库名称]” 。其中参数与 mysql 命令大致相同,-u 参数用于定义登录数据库的账户名称,-p 参数代表密码提示符。下面将 linuxprobe 数据库中的内容导出成一个文件,并保存到 root 管理员的家目录中:
# mysqldump -u root -p linuxprobe > /root/linuxprobeDB.dump
Enter password:(此处输入root管理员在数据库中的密码)
然后进入 MariaDB 数据库管理系统,彻底删除 linuxprobe 数据库,这样 mybook 数据表单也将被彻底删除。然后重新建立 linuxprobe 数据库:
MariaDB [(none)]> DROP DATABASE linuxprobe;
Query OK, 1 row affected (0.04 sec)
MariaDB [(none)]> SHOW databases;
+--------------------+
| Database |
+--------------------+
| infor ** tion_sche ** |
| mysql |
| perfor ** nce_sche ** |
+--------------------+
3 rows in set (0.02 sec)
MariaDB [(none)]> CREATE DATABASE linuxprobe;
Query OK, 1 row affected (0.00 sec)
接下来是见证数据恢复效果的时刻!使用输入重定向符把刚刚备份的数据库文件导入到mysql 命令中,然后执行该命令。接下来登录到 MariaDB 数据库,就又能看到 linuxprobe 数据库以及 mybook 数据表单了。数据库恢复成功!
# mysql -u root -p linuxprobe < /root/linuxprobeDB.dump
Enter password: (此处输入root管理员在数据库中的密码)
# mysql -u root -p
Enter password: (此处输入root管理员在数据库中的密码)
MariaDB [(none)]> use linuxprobe;
Reading table infor ** tion for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [linuxprobe]> SHOW tables;
+----------------------+
| Tables_in_linuxprobe |
+----------------------+
| mybook |
+----------------------+
1 row in set (0.05 sec)
MariaDB [linuxprobe]> DESCRIBE mybook;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| name | char(15) | YES | | NULL | |
| price | int(11) | YES | | NULL | |
| pages | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.02 sec)
.扫码咨询与免费使用
申请免费使用