programing

옵션을 사용하여 명령줄에서 .sql 파일을 내보내고 가져오려면 어떻게 해야 합니까?

randomtip 2022. 9. 5. 22:49
반응형

옵션을 사용하여 명령줄에서 .sql 파일을 내보내고 가져오려면 어떻게 해야 합니까?

중복되지 않음!명령줄에서 내보내는 동안 phpmyadmin 기능을 찾습니다.

명령줄에서 MySQL 데이터베이스로 .sql 파일을 내보내고 Import합니다.

MySQL에서 .sql 파일을 내보내기 위한 명령어가 있습니까?그럼 어떻게 수입하나요?

내보내기/가져오기 수행 시 외부검사 활성화/비활성화 또는 내보내기 전용 테이블 구조와 같은 제약 조건이 있을 수 있습니다.

이러한 옵션을 설정할 수 있습니까?mysqldump?

옵션의 몇 가지 예

여기에 이미지 설명 입력

다음 명령을 입력하여 SQL 데이터 파일을 가져옵니다.

$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql

이 예에서는 vivek를 사용자 이름으로 사용하여 'data.sql' 파일을 'blog' 데이터베이스로 가져옵니다.

$ mysql -u vivek -p -h localhost blog < data.sql

전용 데이터베이스 서버가 있는 경우 다음과 같이 localhost hostname을 실제 서버 이름 또는 IP 주소로 바꿉니다.

$ mysql -u username -p -h 202.54.1.10 databasename < data.sql

데이터베이스를 내보내려면 다음을 사용합니다.

mysqldump -u username -p databasename > filename.sql

주의:<그리고.>기호가 표시됩니다.

SQL 쉘을 이미 실행하고 있는 경우source명령어를 사용하여 데이터를 Import합니다.

use databasename;
source data.sql;

mysqldump는 개별 데이터베이스를 덤프할 때 명시적으로 명시되지 않는 한 데이터베이스 이벤트, 트리거 및 루틴을 덤프하지 않습니다.

mysqldump -uuser -p db_name --events --triggers --routines > db_name.sql

다음 명령을 사용하여 내보낼 수 있습니다.

mysqldump --syslog --user=root --password your_db_name > export_into_db.sql

생성된 파일은 이 명령을 실행한 디렉토리에서 사용할 수 있습니다.

이제 명령어를 사용하여 mysql에 로그인합니다.

mysql -u[discl] -p

그런 다음 파일 경로와 함께 "source" 명령을 사용합니다.

데이터베이스 전체를 파일로 덤프합니다.

mysqldump -u USERNAME -p password DATABASENAME > FILENAME.sql

해라

mysqldump databaseExample > file.sql

저는 가장 높은 게시물 뒤에 코멘트를 할 만한 충분한 평판이 없기 때문에 여기에 덧붙입니다.

Linux 플랫폼에서 '|'를 사용하여 디스크 공간을 절약합니다.

thx @Hariboo, 이벤트/트리거/루틴트 파라미터 추가

mysqldump -x -u [uname] -p[pass]  -C --databases db_name  --events --triggers --routines | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/ '  | awk '{ if (index($0,"GTID_PURGED")) { getline; while (length($0) > 0) { getline; } } else { print $0 } }'  | grep -iv 'set @@' | trickle -u 10240 mysql -u username -p -h localhost DATA-BASE-NAME

몇 가지 문제/문제:

오류: ......LOCK TABLES를 사용할 때 존재하지 않습니다.

# --lock-all-tables,-x , this parameter is to keep data consistency because some transaction may still be working like schedule.
# also you need check and confirm: grant all privileges on *.* to root@"%" identified by "Passwd";

866행의 ERROR 2006 (HY000) : MySQL Server has away mysqldump : errno 32 on write

# set this values big enough on destination mysql server, like: max_allowed_packet=1024*1024*20
# use compress parameter '-C'
# use trickle to limit network bandwidth while write data to destination server

32730 행의 ERROR 1419 (HY000): SUPER 권한이 없고 이진 로그가 활성화되어 있습니다(안전성이 낮은 log_bin_trust_function_creators 변수를 사용하는 이 좋습니다).

# set SET GLOBAL log_bin_trust_function_creators = 1;
# or use super user import data

138행의 ERROR 1227(42000):접속이 거부되었습니다.이 조작에는 SUPER 권한(적어도1개)이 필요합니다.쓰기 시 errno 32가 있습니다.

# add sed/awk to avoid some privilege issues

이게 도움이 되길 바래!

다음 스크립트를 사용하여 다음 링크에서 지정된 단말기에서 데이터베이스를 내보내거나 가져올 수 있습니다.https://github.com/Ridhwanluthra/mysql_import_export_script/blob/master/mysql_import_export_script.sh

echo -e "Welcome to the import/export database utility\n"
echo -e "the default location of mysqldump file is: /opt/lampp/bin/mysqldump\n"
echo -e "the default location of mysql file is: /opt/lampp/bin/mysql\n"
read -p 'Would like you like to change the default location [y/n]: ' location_change
read -p "Please enter your username: " u_name
read -p 'Would you like to import or export a database: [import/export]: ' action
echo

mysqldump_location=/opt/lampp/bin/mysqldump
mysql_location=/opt/lampp/bin/mysql

if [ "$action" == "export" ]; then
    if [ "$location_change" == "y" ]; then
        read -p 'Give the location of mysqldump that you want to use: ' mysqldump_location
        echo
    else
        echo -e "Using default location of mysqldump\n"
    fi
    read -p 'Give the name of database in which you would like to export: ' db_name
    read -p 'Give the complete path of the .sql file in which you would like to export the database: ' sql_file
    $mysqldump_location -u $u_name -p $db_name > $sql_file
elif [ "$action" == "import" ]; then
    if [ "$location_change" == "y" ]; then
        read -p 'Give the location of mysql that you want to use: ' mysql_location
        echo
    else
        echo -e "Using default location of mysql\n"
    fi
    read -p 'Give the complete path of the .sql file you would like to import: ' sql_file
    read -p 'Give the name of database in which to import this file: ' db_name
    $mysql_location -u $u_name -p $db_name < $sql_file
else
    echo "please select a valid command"
fi

언급URL : https://stackoverflow.com/questions/11407349/how-to-export-and-import-a-sql-file-from-command-line-with-options

반응형