• 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-- 

  • 相关阅读:
    Grodno 2015 (Urozero May 2015 Day 5) D Triangles
    Flea Circus(Project Euler 213)
    Prime triplets (Project Euler 196)
    ACM 博弈(难)题练习 (第二弹)
    Crosses Puzzles zoj 4018 (zju校赛)
    Petrozavodsk Summer-2015. Ivan Smirnov Contest 1 B Bloom
    ACM 博弈(难)题练习 (第一弹)
    2017 ACM区域赛(南宁站) 参赛流水账
    2017 CCPC 杭州 流水账
    2017 ACM区域赛(西安) 参赛流水账
  • 原文地址:https://www.cnblogs.com/ibgo/p/5956514.html
Copyright © 2020-2023  润新知