文章詳情頁
目前學習到的常用命令之Mariadb
瀏覽:24日期:2023-03-30 13:34:15
在諸如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");
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");
相關文章:
排行榜
