sql basis (pgsql & mysql)

  1. Into the local database

    1
    psql resumehack_development
  2. Enter the database server
    console directly connected to the database bin / rails dbconsole production

  3. Modify the database password
    password

  4. View database size

    command:

    1
    SELECT pg_size_pretty(pg_database_size('database name'));

All queries and tables are arranged according to size

1
select table_name, pg_relation_size(quote_ident(table_name)) from information_schema.tables where table_schema = 'public' order by 2;
  1. Single copy table data
    pg_dump -U postgres -table jd_temps -Fc test_production> /home/apps/jd_temps.sql

scp [email protected]:/home/apps/jd_temps.sql /Users/dailanyi/Downloads/

psql resumehack_development
DROP TABLE jd_temps;

pg_restore -U dailanyi –dbname resumehack_development –table=jd_temps /Users/dailanyi/Downloads/jd_temps.sql

psql resumehack_development
ALTER TABLE jd_temps ADD PRIMARY KEY (id);

  1. Imported to the local database

    1
    psql resumehack_development < /Users/dailanyi/Desktop/PostgreSQL.sql
  2. restore db

    1
    2
    psql -U postgres -d wondercv_test -c "drop schema public cascade; create schema public;"
    psql --set ON_ERROR_STOP=on -U postgres wondercv_test < #{db_unzip_file}

mysql

Database from local to remote copy

1. First check whether the remote backup file
is not created a:
mysqldump-uroot--p password database name> guided by the document name database .sql

2. locally run
scp -P port number root @ server name: / opt / app / Process Name / current / lead out of the database file name .sql.

3. The remote copy down the database backup documents poured into the local database
mysql -uroot -p local database password for the local database name <guided by the document name database .sql

ps:

  1. Remote Download:

    1
    scp -r [email protected]:/home/apps/main-backup/resumehack_pg/2018.12.02.15.30.02 /Users/dailanyi/Downloads/
  2. Upload documents to a local server

    1
    scp /path/local_filename username@servername:/path
  3. In the documentation directory is not run inside the console
    Export RAILS_ENV = Production's
    Rails Runner /home/apps/download_interview_data.rb

Original link large column  https://www.dazhuanlan.com/2019/08/15/5d5514081e2ac/

Guess you like

Origin www.cnblogs.com/chinatrump/p/11416254.html