Wednesday, March 4, 2020

MySQL MariaDB example statements

MariaDB / MySQL basic command references

Add a column

ALTER TABLE websites
  ADD host_name varchar(40)
    AFTER server_name;
Add some data to a column

or maybe
update cdr set dst ='s' where uniqueid = '1583251639.8494'
Modify a column title
ALTER TABLE websites
  MODIFY host_name varchar(50);
Show database column names

show columns from TABLENAME
Select data and get the most recent record

select * from cdr where clid like '%5DATA%' and calldate like '%2020-03%' order by calldate desc limit 1

List databases 
SHOW DATABASES;
Change active database 
USE dbname;
Change to the “system” database 
USE mysql;
Show tables in active database 
SHOW TABLES;
Show table properties 
DESCRIBE tablename;
List all users 
SELECT user,host,password FROM mysql.user;
List databases 
SELECT host,db,user FROM mysql.db;
Quit exit or Ctrl-D
Count the rows
select count(*) from cdr;
Count specific rows
select count(*) from TABLE where COLUMN like %VAL%;

Show the current port in 
mysql> SHOW VARIABLES WHERE Variable_name = 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.00 sec)


No comments:

Post a Comment