MySQL/MariaDB Reference

From The Linux Source
Jump to: navigation, search
  • List Databases
 mysql> show databases;
  • List Tables
 mysql> show tables;
  • Change Passwords

Note: the mysqladmin command should be run from a shell script, so as to not have this critical password exposed in the command history (preferred/more secure method) - make sure to delete the shell script after running

 # mysqladmin -u root password 'new-password'
  • Delete Database
 mysql> drop database test;
  • Creating a new DB and assigning permissions

Command line/scripted
Note: the echo command should be run from a shell script, so as to not have a critical password exposed in the command history (preferred/more secure method) - make sure to delete the shell script after running

 # mysqladmin -p create wikidb
 # echo "grant index, create, select, insert, update, delete, alter, lock tables on wikidb.* to 'wikiuser'@'localhost' identified by 'password';" | mysql -p

mySQL command line
Note: this is added to the mysql command history (not a good idea to leave the password exposed):

 # mysql -p
 mysql> create database wikidb;
 mysql> grant index, create, select, insert, update, delete, alter, lock tables on wikidb.* to 'wikiuser'@'localhost' identified by 'password';
  • Table Structure
describe SystemEvents;
  • View Data (Some Query Examples)
select * from user;
select Host,User,Grant_priv from user;
select Host,Db,User,Grant_priv from db;
select * from SystemEvents where SysLogTag='CROND';
select * from SystemEvents limit 5;
select * from SystemEvents where SysLogTag like '%[%' limit 5; 
  • Modify Data
update SystemEvents set SysLogTag='CROND:' where SysLogTag='CROND';
update SystemEvents set SysLogTag='sshd:' where SysLogTag like 'sshd[%';
  • Delete From Table
delete from SystemEvents where SysLogTag='CROND';