1

Sorry for me being a novice, I know this looks like a dumb question. I'm trying to follow this very beginner's tutorial. It seems the instructor is using the employees.sql database from this sample database. If I just run the command:

select * from employees;

I get the error

Error Code: 1046. No database selected Select the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar.

I tried opening the employees.sql on the side:

                          

but then running it returns the error message:

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'source load_departments.dump' at line 1

And this similar issue on their GitHub repository also doesn't help much. I tried following the installation instructions on the sample database repository:

mysql < employees.sql

however, I get another error:

ERROR 1045 (28000): Access denied for user 'foobar'@'localhost' (using password: NO)

I would appreciate it if you could help me know what are the prerequisites in the step by step form to be able to follow the rest of this tutorial.

P.S. I'm on macOS Catalina and my Workbench version is 8.0, and MySQL

mysql Ver 8.0.19 for osx10.15 on x86_64 (Homebrew)

following the instructions here.

11
  • 1
    Your user error indicated you're logged in on a user that doesn't have the required privileges mentioned on the page you linked. I just tried it with a MySQL server installed on my pc and through Workbench on user root and it worked. Aside from a built-in error the employees.sql seems to have when trying to import departments dump, everything works fine. Commented Mar 26, 2020 at 12:24
  • @t1f I just installed MySQL and MySQL Workbench following these instructions. I followed the mysql_secure_installation steps to set a password for the root user and then used the password in Workbench. Any step by step instruction about how should I change that so I have the previlages? Commented Mar 26, 2020 at 12:30
  • 1
    What operating system are you using? Commented Mar 26, 2020 at 12:31
  • 1
    @Foad As you should, it's always good to learn to get 'dirty' too, not being reliant on GUIs and such, I was simply stating that for this circumstance, it would potentially make it more difficult to understand since you're already having problems with the GUI. Check out dev.mysql.com/doc/mysql-getting-started/en and then dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-commands.html and then a2hosting.com/kb/developer-corner/mysql/… and so forth. Lots of resources available, do some google searches for mysql command line Commented Mar 26, 2020 at 12:47
  • 1
    @t1f thanks a lot. Sure it makes sense that I first figure the GUI out and then move to the more advances command-line interface. Commented Mar 26, 2020 at 12:49

2 Answers 2

1

There is a small error in that repository.

You'll have to fix that.

Open up the employees.sql with an editor, like Notepad++ for example then go to the bottom of the file where you will find this:

SELECT 'LOADING departments' as 'INFO';
source load_departments.dump ;
SELECT 'LOADING employees' as 'INFO';
source load_employees.dump ;
SELECT 'LOADING dept_emp' as 'INFO';
source load_dept_emp.dump ;
SELECT 'LOADING dept_manager' as 'INFO';
source load_dept_manager.dump ;
SELECT 'LOADING titles' as 'INFO';
source load_titles.dump ;
SELECT 'LOADING salaries' as 'INFO';
source load_salaries1.dump ;
source load_salaries2.dump ;
source load_salaries3.dump ;

source show_elapsed.sql ;

Try replacing:

"SELECT 'LOADING departments' as 'INFO';
source load_departments.dump ;"

with

"SELECT 'LOADING departments' as 'INFO';
source C:/load_departments.dump ;
  • Where C:/ should be the actual path to the file in question, on your computer.
  • Do this for every line in the file there at the end, adding the appropriate path.

Now import employees.sql and run it and see if it works.

If it doesn't, then try doing it this way:

Delete only the following code and save the changes to the file.

SELECT 'LOADING departments' as 'INFO';
source load_departments.dump ;
SELECT 'LOADING employees' as 'INFO';
source load_employees.dump ;
SELECT 'LOADING dept_emp' as 'INFO';
source load_dept_emp.dump ;
SELECT 'LOADING dept_manager' as 'INFO';
source load_dept_manager.dump ;
SELECT 'LOADING titles' as 'INFO';
source load_titles.dump ;
SELECT 'LOADING salaries' as 'INFO';
source load_salaries1.dump ;
source load_salaries2.dump ;
source load_salaries3.dump ;

Now continue doing this:

  • Open Workbench

  • Add a new MySQL connection to your local MySQL server.

Make sure you are connecting/adding the root user or another user that has the following privileges, to the connection:

SELECT, INSERT, UPDATE, DELETE, 
CREATE, DROP, RELOAD, REFERENCES, 
INDEX, ALTER, SHOW DATABASES, 
CREATE TEMPORARY TABLES, 
LOCK TABLES, EXECUTE, CREATE VIEW
  • Double click and open your newly formed connection

  • Go to Left-Upper corner, click on File then click on Open SQL Script and select the employees.sql from the repository you downloaded and click the lightning icon.

After that:

  • use the Open SQL Script again and open load_employees.dump then click the Lightning icon again in the newly opened file.

  • use the Open SQL Script again and open load_departments.dumpthen click the Lightning icon again in the newly opened file.

  • use the Open SQL Script again and open load_dept_emp.dumpthen click the Lightning icon again in the newly opened file.

  • use the Open SQL Script again and open load_dept_manager.dumpthen click the Lightning icon again in the newly opened file.

  • use the Open SQL Script again and open load_titles.dump then click the Lightning icon again in the newly opened file.

  • use the Open SQL Script again and open load_salaries1.dumpthen click the Lightning icon again in the newly opened file.

  • use the Open SQL Script again and open load_salaries2.dumpthen click the Lightning icon again in the newly opened file.

  • use the Open SQL Script again and open load_salaries3.dump then click the Lightning icon again in the newly opened file.

Now you're done importing the database. You can now do your select * from employees query.

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

13 Comments

thanks. How can I configure those privileges? This is what I see when I open the Workbench
Give it a connection name. Click on store in keychain next to password and add the password (not sure if it's different, I'm on Windows and it says in vault for me, not in keychain) then click Test connection in the lower right - if everything works fine click Ok then double-tap the newly formed connection in your workbench window. If everything is fine and you logged in, further follow the instruction in my answer above.
The Test Connection result is this so I think I can follow the rest of the steps, I suppose.
@Foad Yup seems fine so far. Follow further and see how it goes.
@Foad Seems alright, since it's official and on a quick look. Test it and see if you still get the loading error. My answer is precisely for that use case, if you get the error while loading the dumps, in which case, I edited and added another quick fix (you need to specify the path to the dumps right in the sql file). If the official approach, via cmd line works for you, by all means, use it ^_^
|
0

OK, I think I have found the solution, and it requires a little bit of command line. If you have followed these instructions to install MySQL and MySQL Workbench using HomeBrew, Then you should already have a user and a password set. Now assuming that you have downloaded this GitHub repository, The you need to go to the downloaded test_db-master and following the instructions here, from your terminal and run the command:

mysql -u <user_name> -p -t < employees.sql

where you replace the <user_name> with the user you want to use. In my case, it is just root. Then it asks for the user's password and you should see the database imported. Now lunch the MySQL workbench. And you should see the employees database in the schemas tab of the left-hand sidebar/panel. Now you need to double click on it, or right-click on it and select set as default schema:

                      

alternatively, you could add

USE employees;

at the top of your script for the first time. Now you are good to go and can run the rest of the queries, following the tutorial.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.