In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Installation
1 add source
Sudo rpm-Uvh https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-3.noarch.rpm
2 installation
Sudo yum install postgresql94-server postgresql94-contrib
3 verify that the installation is successful
Sudo rpm-aq | grep postgres
The following results should occur
Postgresql94-libs-9.4.6-1PGDG.rhel6.x86_64
Postgresql94-server-9.4.6-1PGDG.rhel6.x86_64
Postgresql94-9.4.6-1PGDG.rhel6.x86_64
Postgresql94-contrib-9.4.6-1PGDG.rhel6.x86_64
4 switch to the postgres account, initialize and start the database
Su postgres
/ usr/pgsql-9.4/bin/initdb-pgdata=/data/postgres-locale=C-encoding=utf8
/ usr/pgsql-9.4/bin/pg_ctl-D / data/postgres-l / data/postgres/psotgres.log start
2.5 use psql to connect to the database (non-postgres users can be used)
Psql-U postgres
Library operation
\ h: check the explanation of the SQL command, such as\ h select.
\?: view a list of psql commands.
\ l: list all databases.
\ C [database_name]: connect to other databases.
\ d: lists all tables for the current database.
\ d [table_name]: lists the structure of a table.
\ du: list all users.
\ e: open a text editor.
\ conninfo: lists the current database and connection information.
Log into the database
Psql-U postgres-W (password)-h 127.0.0.1
Create a database
Create database databa_name
Backup database
Pg_dump-h 127.0.0.1-U postgres databasename > / data/backup_name.sql
Import database
Psql-h localhost-U postgres-d databasename < / data/backup_name.sql
Modify database password
ALTER USER postgres WITH PASSWORD 'postgres'
Table operation
Create a new table
CREATE TABLE user_tbl (name VARCHAR (20), signup_date DATE)
Insert data
INSERT INTO user_tbl (name, signup_date) VALUES ('Zhang San', '2013-12-22')
Select record
SELECT * FROM user_tbl
Update data
UPDATE user_tbl set name ='Li Si 'WHERE name =' Zhang San'
Delete record
DELETE FROM user_tbl WHERE name ='Li Si'
Add a field
ALTER TABLE user_tbl ADD email VARCHAR (40)
Update structure
ALTER TABLE user_tbl ALTER COLUMN signup_date SET NOT NULL
Rename field
ALTER TABLE user_tbl RENAME COLUMN signup_date TO signup
Delete a field
ALTER TABLE user_tbl DROP COLUMN email
Rename the form
ALTER TABLE user_tbl RENAME TO backup_tbl
Delete form
DROP TABLE IF EXISTS backup_tbl
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.