如何将MySQL Workbench的.mwb数据库架构部署至Ubuntu的MySQL服务器?
Hey there! Let's walk through getting your local MySQL Workbench schema (.mwb file) up and running on your Ubuntu 16.04 MySQL server. It's a straightforward process—here's how to do it step by step:
Step 1: Export your .mwb file to a SQL script
MySQL servers don't understand .mwb files directly, so first we need to convert it into an executable SQL script:
- Open your .mwb file in MySQL Workbench.
- Go to the top menu and select Database > Forward Engineer.
- Follow the wizard prompts:
- Confirm your local MySQL connection (if prompted).
- Choose to include options like creating the database, table structures, indexes, and any data you want to migrate (if applicable).
- At the final step, select "Export to Self-Contained File" and save the resulting
.sqlfile to your local machine.
Step 2: Transfer the SQL script to your Ubuntu server
You'll need to get the .sql file onto your Ubuntu server. The easiest way is using scp from your local terminal:
scp /path/to/your/local/schema.sql your-ubuntu-username@your-server-ip:/home/your-ubuntu-username/
Replace the placeholders with your actual local file path, Ubuntu username, and server IP address. Alternatively, you can use an FTP tool like FileZilla if you prefer a GUI.
Step 3: Run the SQL script on the Ubuntu MySQL server
Now it's time to execute the script to create your schema:
- First, log into your Ubuntu server via SSH if you haven't already.
- Ensure the MySQL service is running:
If it's not running, start it with:sudo systemctl status mysqlsudo systemctl start mysql - Run the SQL script. You can do this in two ways:
- Option 1 (Interactive MySQL shell):
Enter your MySQL root password when prompted, then run:mysql -u root -p-- If your SQL script doesn't include creating the database, run this first CREATE DATABASE your-database-name; USE your-database-name; SOURCE /home/your-ubuntu-username/schema.sql; - Option 2 (Direct shell execution):
This skips the interactive shell—perfect for automation:
Note: If your script creates the database automatically, you can omitmysql -u root -p your-database-name < /home/your-ubuntu-username/schema.sqlyour-database-namefrom the command.
- Option 1 (Interactive MySQL shell):
Step 4: Verify the schema is deployed correctly
To make sure everything worked as expected:
- Log into the MySQL shell again:
mysql -u root -p your-database-name - Run this command to list all tables in the database:
SHOW TABLES;
You should see all the tables from your .mwb schema listed here. If you included data in the export, run a quick SELECT * FROM your-table-name LIMIT 5; to confirm the data was imported correctly.
Quick Tips
- Double-check that your MySQL user (root or another admin user) has sufficient permissions to create databases and tables.
- If your schema includes custom functions, stored procedures, or triggers, make sure the export script included them—you can verify this by opening the .sql file in a text editor.
- If you run into permission errors when accessing the SQL script on the server, adjust the file permissions with
chmod 644 /home/your-ubuntu-username/schema.sql.
内容的提问来源于stack exchange,提问作者No110

