Detailed steps for installing the Postgresql database in Ubuntu: ubuntupostgresql
Introduction
As we all know, PostgreSQL is a free object-relational database server (Database Management System). It is very easy to install Postgresql In ubuntu. I will not talk about it much below, let's take a look at the detailed introduction.
The installation method is as follows:
1. Install the Postgresql server and client:
sudo apt-get install postgresql postgresql-client
2. After the installation is complete, Postgresql must be started. The following are some common operation commands:
# View sudo/etc/init. d/postgresql status # Start sudo/etc/init. d/postgresql start # Stop sudo/etc/init. d/postgresql stop # restart sudo/etc/init. d/postgresql restart
3. Create a new database user root and define it as a Super User:
sudo -u postgres createuser --superuser root
4. Set the root user password:
sudo -u postgres psql\password root\q
5. Create a database mydb:
sudo -u postgres createdb -O root test
6. Rename the database:
alter database mydb rename to mynewdb;
7. log on to the database:
psql -U root -d test -h 127.0.0.1 -p 5432
-U specifies the user,-d specifies the database,-h specifies the server, and-p specifies the port.
8. Common console commands:
- \ H: view the explanations of SQL commands, such as \ h select.
- \? : View the psql command list.
- \ L: list all databases.
- \ C [database_name]: connects to other databases.
- \ D: list all tables of the current database.
- \ D [table_name]: list the structure of a table.
- \ Du: list all users.
- \ E: Open the text editor.
- \ Conninfo: lists information about the current database and connection.
9. database operations:
Database Operations are common SQL statements, but PostgreSQL syntax is available. For details, see the documentation.
Create a table:
create table users ( id serial primary key, username varchar(20), password varchar(20));
Insert data:
insert into users(username, password) values('admin', 'admin');
Query data
select * from users;
10. Install the graphic interface client PgAdmin. Who else needs to use SQL to create a table? After all, time is life:
sudo apt-get install pgadmin3
Note: Some of the content in this article comes from online materials. If there is any infringement, please let us know.
Summary
The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.