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