MacOS terminal import/export sql script

Terminal import sql script

For example, import a mysqlscript file casaba.sql, the path is/Users/superfarr/Desktop/casaba.sql

  • If there is a statement to create a database in the script, we do not need to create it again, if not, we need to create it ourselves

The following process is 没有a tutorial for creating database statements in scripts

Terminal input:

mysql -u root -p

Enter password with password

After entering the MySQL command line

CREATE DATABASE casaba;
USE casaba;

SOURCE 『Drag and drop the .sql file directly to the terminal to automatically complete its file directory』

SOURCE /Users/superfarr/Desktop/casaba.sql;

Terminal export sql script

Suppose you need to export the sql script of the database named blog_db

cd "Open the file location where the .sql file is to be generated", such as in the blog directory on the desktop

cd /Users/xx/Desktop/blog

Then execute

mysqldump -u root -p blog_db>blog_db.sql

If there is a password, just enter the password

Check which database is currently in use

select database(); 

Guess you like

Origin blog.csdn.net/weixin_44471490/article/details/112974893