您的位置:首页技术文章
文章详情页

目前学习到的常用命令之Mariadb

【字号: 日期:2023-03-30 13:34:15浏览:14作者:猪猪
在诸如Debian上,安装mariadb。

sudo apt install mariadb-server mariadb-client
检查相应数据库版本。

mysqladmin --version
修改数据库密码。

mysqladmin -u root password "{yourpassword}";
用账号密码,登录数据库。

mysql -u root -p
用root用户打开mariadb。

sudo mariadb

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.5.15-MariaDB-0+deb11u1 Debian 11

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

Type "help;" or "\h" for help. Type "\c" to clear the current input statement.
下面是在数据库之命令行界面中操作,不是Linux本身之终端。

使用某个数据库。

use mysql
显示当前数据库。

show databases;
创建数据库。

CREATE DATABASE test;
删除特定表。

DROP TABLE products_tbl
显示表中的列。

SHOW COLUMNS FROM tbl;
选中表中的全部。

SELECT * from tbl
显示特定列,从特定表。

SELECT name from tbl;
显示特定列,从特定的库和表。

SELECT name from test.tbl;
显示特定列,从特定的库和表,根据特定的列之值。

SELECT name from test.tbl WHERE name = "好吧啦";
查看表结构。

desc tbl
改变特定表,增加特定列。

alter table tbl add age int(10);
更新表,设置特定列的值,位置是某列的值所对应的。

UPDATE tbl SET age = 61 WHERE id=981;
UPDATE tbl SET age = 65 WHERE name="Marx";
删除,从特定表,位置是某列的值所对应的。

delete from tbl where id=211;
创建表,设定各列。

CREATE TABLE economists(  
-> id INT NOT NULL AUTO_INCREMENT,
-> name VARCHAR(100) NOT NULL,
-> born DATE,
-> dead DATE,
-> book VARCHAR(100) NOT NULL,
-> PRIMARY KEY (id)
-> );
显示当前数据库中的表。

show tables;
展示列,从特定的表。

SHOW COLUMNS FROM economists;
向特定表中插入数据。

INSERT INTO tbl (id, name) VALUES(981, "好吧啦");
INSERT INTO tbl (id, name, age) VALUES(1818, "Marx", 88);
INSERT INTO economists (id, name, born, dead, book) VALUES(0, "Karl Marx", "1818-05-05", "1883-03-14", "Das Kapital");
相关文章: