Then, simply do like this:. Remember where your SQL file is. If you want to access it from the Project directory then you can do like this:. If you already have the database, use the following to import the dump or the sql file:. Note: if your terminal is not in the location where the dump or sql file exists, use the relative path in above.
To import an SQL file into a database make sure you are in the same directory as the SQL file or supply the full path to the file , do:.
Go to the directory where you have the MySQL executable. I think it's worth mentioning that you can also load a gzipped compressed file with zcat like shown below:. You do not need to specify the name of the database on the command line if the. Just make sure you are connecting with a user that has the permissions to create the database, if the database mentioned in the. What is fun, if we are importing a large database and not having a progress bar. Use Pipe Viewer and see the data transfer through the pipe.
For others, refer to pv - Pipe Viewer. Having utf8-collation in the exported tables it's required to use this command:. One comment mentioned also that if a database never exists an empty database had to be created first. This might be right in some cases but depends on the export file. If the exported file includes already the command to create the database then the database never has to be created in a separate step, which even could cause an error on import.
So on import, it's advisable to have a look first in the file to know which commands are included there, on export, it's advisable to note the settings, especially if the file is very large and hard to read in an editor. If you use another database version consider searching for the corresponding version of the manual too. The mentioned links refer to MySQL version 5. EDIT: The same parameters are working for mysqldump too. So while the commands for export and import are different, the mentioned parameters are not.
Add the --force option :. I thought it could be useful for those who are using Mac OS X :. Providing credentials on the command line is not a good idea. The above answers are great, but neglect to mention. Here is a sample,. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more.
Ask Question. Asked 8 years, 6 months ago. Active 24 days ago. Viewed 4. I get syntax errors. How can I import this file without a problem? Do I need to create a database first? Peter Mortensen Jaylen Jaylen Whats with these duplicate guys? This indeed is a helpful question with its own purpose — Valentino Pereira.
ValentinoPereira have you checked original question dates before determine duplicate guys — AZinkey. After I have checked all answers below, I must say you missed a very important clue for those people who wants to help. You failed to specify the exact command when you dump data out of the database. Show 3 more comments. Active Oldest Votes. Active Oldest Votes. Improve this answer. Community Bot 1. There has to be no space between -p and password — tombom.
What if I don't have a password? Then skip password parameter. You can also import an. Nick Chammas Mike S. You are missing the password in command. Use the following. Nitesh Nitesh. After that, restart your MySQL server.
Mat 9, 3 3 gold badges 40 40 silver badges 40 40 bronze badges. The Overflow Blog. Podcast Making Agile work for data science. From the normal command line, you can import the dump file with the following command:. If any errors occur during the process, mysql will print them to the terminal instead. To check if the import was successful, log in to the MySQL shell and inspect the data.
You then imported that data dump into a new database. You can learn more about from the official mysqldump documentation page.
I like making impossible things possible. And I need tea. Where would you like to share this to? Twitter Reddit Hacker News Facebook. Share link Tutorial share link. Sign Up. DigitalOcean home. Community Control Panel. Hacktoberfest Contribute to Open Source. Introduction Importing and exporting databases is a common task in software development.
0コメント