头歌数据库备份与恢复

时间:2024-06-01 16:51:24

第1关:数据库的备份和恢复

    mysql -uroot -p123123 -h127.0.0.1 < /data/workspace/myshixun/src/data.sql
    mysqldump -u root -p studb student> /student_bk.sql
    mysql -uroot -p123123 -h127.0.0.1 -e "create database studb2;"
    mysql -u root -p123123 studb2 < /student_bk.sql  

第2关:数据库表的导出

    chmod 777 /
    vim /etc/mysql/my.cnf 
    [mysqld]
    secure-file-priv="/"
    service mysql restart
    mysql -u root -p123123 studb2 
    SELECT * FROM studb.student INTO OUTFILE "/student_out.txt" LINES TERMINATED BY "\n"; 

第3关:二进制日志

    vim /etc/mysql/my.cnf -->
        [mysqld]
        log-bin=/binlog.log
    service mysql restart
    mysql -u root -p123123  --> FLUSH LOGS;

第4关:使用二进制日志还原数据

    mysql -u root -p123123 -->
        USE studb;
        CREATE TABLE member
        (id INT AUT