信创环境下三个开源数据库:SQLite、MariaDB(MySQL)和postgreSQL(瀚高数据库免费版)基本操作

在信创环境下,常用的免费数据库主要是:SQLite、MariaDB(MySQL)和postgreSQL(瀚高数据库免费版),可以在一些产品中内嵌使用。

  • SQLite作为单文件数据库,不需要后台服务,预装在几乎所有的国产Linux系统中
  • MariaDB也可以在很多信创服务器中进行了预装
  • postgreSQL也是可以在很多信创服务器中可以安装(或者使用瀚高数据库的Lite免费版)

一、MariaDB(MySQL)数据库服务器

MariaDB/MySQL监听3306端口,可以用netstat -ntlp|grep 3306查看是否启动MariaDB服务,其控制命令有:

启动MariaDB命令:systemctl start mariadb.service
停止MariaDB命令:systemctl stop mariadb.service
重启MariaDB命令:systemctl restart mariadb.service
查看MariaDB状态:systemctl status mariadb.service
自动启动MariaDB服务:systemctl enable mariadb.service

在信创服务器上MariaDB基本操作命令示例如下:

[root@localhost ~]# mysql --version
mysql  Ver 15.1 Distrib 5.5.56-MariaDB, for Linux (mips64el) using readline 5.1

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16819
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| vvasdb             |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> use mysql
Reading table information 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 * from users;
ERROR 1146 (42S02): Table 'mysql.users' doesn't exist
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
......
| user                      |
+---------------------------+
24 rows in set (0.00 sec)

MariaDB [mysql]> select host,user,password from user;
+-----------------------+---------+-------------------------------------------+
| Host                  | User    | Password                                  | 
+-----------------------+---------+-------------------------------------------+
| localhost.localdomain | root    | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | 
| 127.0.0.1             | root    | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | 
| ::1                   | root    | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | 
| localhost             | vvasdbo | *4BEF554AEC54893F97630EAC3BBEF156479EF606 | 
| %                     | root    | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | 
+-----------------------+---------+-------------------------------------------+
6 rows in set (0.00 sec)

MariaDB [mysql]> quit;
Bye

mysql命令行也支持远程操作:#mysql -h 192.168.1.87 -u root -p

二、postgreSQL(瀚高数据库)数据库服务器

postgreSQL/瀚高监听5432端口,可以用netstat -ntlp|grep 5432查看是否启动postgreSQL服务,其控制命令有:

[root@localhost ~]# source /opt/HighGoDB-5.0.0-lite/bin/highgodb.env
[root@localhost ~]# /opt/HighGoDB-5.0.0-lite/bin/pg_ctl status|start|stop|restart

直接用pg_ctl start启动,必须设置环境变量PGDATA(上面的source命令就包含PGDATA设置)。

或者手动指定启动的目录,例如pg_ctl -D /opt/HighGoDB-5.0.0-lite/bin/postgres start,否则会报错。

在UNIX平台中安装PostgreSQL之后,PostgreSQL会在系统中创建一个名为“postgres”当用户。PostgreSQL的默认用户名和数据库也是“postgres”,不过没有默认密码。

在信创服务器上postgreSQL基本操作命令示例如下(httc是用户名,也有一个httc数据库):

[root@localhost ~]# source /opt/HighGoDB-5.0.0-lite/bin/highgodb.env 
[root@localhost ~]# 
[root@localhost ~]# /opt/HighGoDB-5.0.0-lite/bin/pg_ctl -V
pg_ctl (PostgreSQL) 10.5
[root@localhost ~]# 
[root@localhost ~]# /opt/HighGoDB-5.0.0-lite/bin/psql -U httc
psql (5.0.0 lite)
httc=# \l
 ????±?   ?3?   | ??? | ??±? |  У??攲   |    Ctype    |     ′戡??      
-----------+--------+----------+-------------+-------------+-------------------
 highgo    | highgo | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 httc      | highgo | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 httcv3    | highgo | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0 | highgo | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/highgo        +
           |        |          |             |             | highgo=CTc/highgo
 template1 | highgo | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/highgo        +
           |        |          |             |             | highgo=CTc/highgo
(5 А???)

httc=# \c httc
您现在已经连接到数据库 "httc",用户 "httc".
httc=# \q
[root@localhost ~]# 

psql命令行也支持远程操作:psql -U pg_user -d pg_db -h pg_host -p 5432

在数据库中的一些命令:

httc=# \l 查看系统中现存的数据库
httc=# \q 退出客户端程序psql
httc=# \c 从一个数据库中转到另一个数据库中,如template1=# \c sales 从template1转到sales
httc=# \dt 查看表
httc=# \d 查看表结构
httc=# \di 查看索引

三、 SQLite

SQLite是单文件数据库,没有后台服务,所有的Linux平台基本都已经预装SQLite3。

在命令行下输入sqlite3进入SQLite管理命令行,常见操作命令有:

<1>打开某个数据库文件,sqlite3  test.db
<2>查看所有的命令介绍,.help
<3>退出当前数据库系统,.quit
<4>显示当前打开的数据库文的位置   .database
<5>显示数据库中所有的表   .tables
在当前的数据库文件中创建一张新表(语句) [注:以;结尾,<>中是我们可变的内容]
create table <table_name>(col1,col2,col3...);
例如:create table people(name,sex,age);
<6>查看表中表头的信息   .schema
<7>显示调整成列模式     sqlite> .mode column         
<8>显示表头    sqlite> .header on

一个基本的操作示例如下:

[root@localhost ~]# sqlite3 /opt/cookies.sqlite 
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .database
seq  name             file                                                      
---  ---------------  ----------------------------------------------------------
0    main             /opt/cookies.sqlite                                       
sqlite> .tables
moz_cookies
sqlite> select * from moz_cookies limit 5;
1||uid|rBADh10OIoQoszYgFQW9Ag==|.i.g-fox.cn|/|2145916555|1589638808144000|1561207429733000|0|0|0|0|0
4||BIDUPSID|64D7156CC4CAB8B8E7FB04C972C0E955|.baidu.com|/|3708691077|1589639253707000|1561207430139001|0|0|0|0|0
5||PSTM|1561207428|.baidu.com|/|3708691077|1589639253707000|1561207430139002|0|0|0|0|0
9||HMACCOUNT|C09A459A1A54B335|.hm.baidu.com|/|2147385600|1589639253780000|1561207440672000|0|0|0|0|0
11||wkview_gotodaily_tip|1|wenku.baidu.com|/view/|1592743441|1589553212581000|1561207441070000|0|0|0|0|0
sqlite> .quit
[root@localhost ~]# 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值