introduce
The installation method is as follows:
1. Install Postgresql server and client:
sudo apt-get install postgresql postgresql-client
2. Normally, Postgresql has been started after installation. Here are some common operation instructions:
# Check the statussudo /etc//postgresql status # start upsudo /etc//postgresql start # stopsudo /etc//postgresql stop # Restartsudo /etc//postgresql restart
3. Create a new database user root and formulate it as a super user:
sudo -u postgres createuser --superuser root
4. Set the password of the root user:
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 in 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, -p specifies the port.
8. Common console commands:
- \h: Check the explanation of SQL commands, such as \h select.
- \?: Check the psql command list.
- \l: List all databases.
- \c [database_name]: Connect to other databases.
- \d: List all tables in the current database.
- \d [table_name]: Lists the structure of a certain table.
- \du: List all users.
- \e: Open the text editor.
- \conninfo: Lists the current database and connection information.
9. Database operations:
The database operation is normal SQL, but it has its own syntax for PostgreSQL. See for detailsDocumentation description。
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 graphical interface client PgAdmin. With this guy, who still uses SQL to build tables? After all, time is life:
sudo apt-get install pgadmin3
Note: Some content in this article comes from online information. If there is any infringement, please let us know.
Summarize
The above is the entire content of this article. I hope the content of this article will be of some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.