mysql sqlite3 postgresql 简明操作

 安装

mysql

$ sudo apt-get install mysql-server

sqlite3

$ sudo apt-get install sqlite3

postgresql

$ sudo apt-get install postgresql

用户

mysql添加/删除用户

添加:
mysql> CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'finley'@'localhost'WITH GRANT OPTION;
删除: mysql
> DROP USER 'user1'@'localhost';

postgresql

$ sudo adduser user1 #先在系统中添加一个用户

$ sudo su - postgres
postgres@debian:~$ psql
postgres=# CREATE USER user1 WITH PASSWORD 'password';

删除用户:
postgres=# DROP user user1;

认证失败见 http://www.cnblogs.com/ibgo/p/5961849.html 

登录/登出

msql

$ mysql -u jack -p
mysql> q

sqlite

$ sqlite3 
sqlite> .q

postgresql

$ psql -U user1 -d exampledb
exampledb=> q

 数据库

mysql  添加/删除数据库

mysql> CREATE DATABASE abc;
mysql> DROP DATABASE abc;

sqlite 添加/删除数据库

$ sqlite3 abc.db  
$ rm abc.db

postgresql添加/删除数据库

postgres=# CREATE DATABASE exampledb OWNER user1;
postgres=# GRANT ALL PRIVILEGES ON DATABASE exampledb to user1;
只有给user1用户赋予创建数据库的权限后他才能创建数据库!这里user1用户只是对exampledb数据库有操作权限。

postgres=# CREATE DATABASE db1;
postgres=# DROP DATABASE db1;

数据表

mysql添加/删除数据表

mysql> CREATE TABLE tb1(id int auto_increment,name varchar(10),primary key(id));
mysql> DROP TABLE tb1;

sqlite添加/删除数据表

sqlite> CREATE TABLE users(id integer primary key autoincrement,name text,age int);
sqlite> DROP TABLE users;

postgresql

exampledb=> CREATE TABLE users(id serial,name VARCHAR(20), signup_date DATE);
exampledb=> DROP TABLE users;
  sqlite3 mysql postgresql
insall $ sudo apt-get install sqlite3 $ sudo apt-get install mysql-server

$ sudo apt-get install postgresql

login $ sqlite3 $ mysql -u jack -p  
logout sqlite> .q mysql> q  
add user  

mysql> CREATE USER 'user1'@'localhost' IDENTIFIED BY 'pass1';

mysql> GRANT ALL PRIVILEGES ON . TO 'finley'@'localhost'WITH GRANT OPTION;

 
delete user   mysql> DROP USER 'user1'@'localhost';  
create database $ sqlite3 abc.db mysql> CREATE DATABASE abc;  
delete database $ rm abc.db mysql> DROP DATABASE abc;  
create table sqlite> CREATE TABLE users(id integer primary key autoincrement,name text,age int); mysql> CREATE TABLE tb1(id int autoincrement,name varchar(10),primary key(id));  
delete table sqlite> DROP TABLE tb1; mysql> DROP TABLE tb1;  

--Continual-- 

原文地址:https://www.cnblogs.com/ibgo/p/5956514.html