Comparison of common PostgreSQL and MySQL commands

Source: Internet
Author: User
Tags mysql commands psql

Original article:

Http://www.phpwell.com /? P = 174

PostgreSQL

MySQL

Service startup:
1) # service PostgreSQL start
2) #/etc/init. d/PostgreSQL start
3) # Su-PostgreSQL
$ Pg_ctl start
PostgreSQL process number: 1210, 1207,

Service startup:
1) # service mysqld start
2) #/etc/init. d/mysqld start
3) # safe_mysqld &

 

MySQL process code 1663

Enter the database for the first time:
# Su-Postgres
$ Createdb (Create a database named Postgres)
$ Psql

Enter the database for the first time:

# MySQL
Mysql> (if this prompt is displayed, it indicates that the prompt is successful)

Create a user: (ajian, password: 123)
# Su-Postgres

$ Psql

= # Create user ajian with password '000000'

Create a user: (ajian, password: 123)
# Grant all privileges on *. * To ajian @ "%" identified by "123 ″

(Note: You can also assign permissions. Here is all)

Create a database (my ):

# Su-Postgres

$ Psql

= # Create database my with owner = ajian template = template1 encoding = 'unicode ';

Create a database (my ):

1) # MySQL

Mysql> Create Database my;

2) # mysqladmin create my

View users and databases:

# Su-Postgres

$ Psql

= # \ L (view database)
= # \ Du (view User)

View users and databases:

1) # MySQL

Mysql> show databases; (view database)

2) # mysqlshow

New User Logon:

(Modify the configuration file first)

# Vi/var/lib/pgsql/data/pg_cmd.conf (Add at the end)

Host All all 127.0.0.1 255.255.255.255 MD5

Restart the service: # service PostgreSQL restart

Login: # Psql-H 127.0.0.1-u ajian my

Password:

New User Logon:

1) # mysql-u ajian-P (logon with password)

2) # MySQL

Mysql> use my;

(Logon without a password is generally used on the local machine)

Create a table (employee ):

= # Create table employee (

(# Employee_id int primary key,

(# Name char (8 ),

(# Sex char (2 ));

Create a table:

> Create Table employee (

-> Employee_id int primary key,

-> Name char (8 ),

-> Sex char (2 ));

View table:

= # \ Dt

View table:

> Show tables;

View the table structure:

= # \ D employee

View the table structure:

> Sescribe employee;

Add data to the table:

= # Insert into employee values

-# ('1', 'zhang ', 'F ');

-# ('2', 'chen', 'M ',);

Add data to the table:

> Insert into employee values

-> ('1', 'zhang ', 'F ');

-> ('2', 'chen', 'M ',);

View table data:

= # Select * From emlpoyee

View table data:

> Select * From emlpoyee;

Create an index (in_employee ):

=# create index in_employee on employee (name);

View indexes:

=#\ di

delete an index:

=# drop index in_employee on employee;

index reconstruction:

=# reindex table employee; (recreate all)

=# reindex in_employee; (rebuilding the specified one)

Create an index (in_employee ):

1)> Create index in_employee on employee (name);

2)> alter table employee add index in_employee (name);

View index:

show index from employee;

delete an index:

1)> drop index in_employee on employee;

2)> alter table emlpoyee drop index in_employee;

Delete table:

= # Drop table employee;

Delete table:

> Drop table employee;

Delete Database: (Note the mark before the command)

1) = # drop database ajian;

2) $ dropdb ajian

Delete Database: (Note the mark before the command)

1)> drop database ajian;

2) # mysqladmin drop ajian

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.