0% found this document useful (0 votes)
1 views

SQL FAQ

The document is a comprehensive FAQ for MySQL users, covering topics such as installation, password recovery, troubleshooting errors, and understanding SQL commands. It provides step-by-step solutions for common issues like uninstalling MySQL, fixing installation problems, and using ROLLBACK effectively. Additionally, it includes explanations of SQL syntax and error codes to assist users in resolving programming challenges.

Uploaded by

Kabir Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

SQL FAQ

The document is a comprehensive FAQ for MySQL users, covering topics such as installation, password recovery, troubleshooting errors, and understanding SQL commands. It provides step-by-step solutions for common issues like uninstalling MySQL, fixing installation problems, and using ROLLBACK effectively. Additionally, it includes explanations of SQL syntax and error codes to assist users in resolving programming challenges.

Uploaded by

Kabir Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

SQL

FAQ
TABLE OF CONTENTS

PREFACE 3

How can I uninstall MySQL (Server + Workbench)? 5

How can I recover the root password/RESET the password/ create a new password? 7

Installation stops at “Starting Server” Configuration Step. What can I do? 9

Configuration stops at “Initializing Database”. How can I fix this? 10

How can I Download MySQL Server and Workbench on a Mac? 11

ROLLBACK doesn’t work. How can I solve this problem? 13

Why do I get Error Code: 1452: Cannot Add or Update Child Row: INSERT record 999903? 14

What does the minus sign ( – ) mean in ORDER BY –a.emp_no DESC;? 15


Back to the Table of Contents

Preface

IMPORTANT – PLEASE DON’T SKIP THIS PART!

Here we will describe the process you need to go through whenever you encounter an error in programming.
Please read the following two pages carefully, as they will surely save you a lot of time and effort in the long
run!

A general note on problem-solving

Even the best programmers out there find it nearly impossible to successfully create the complex code that
delivers the desired output the first time they write it. So, we can say coding is all about trying, stumbling
upon an error, reading the obtained error message, finding a solution, and then applying it. Over and over
again. In fact, this process is repeated infinitely.

Therefore, as a programmer, you need to develop the skill to quickly and efficiently identify and solve
problems that occur while you are coding.

What should I do when I encounter a coding error?

With this question in mind, we will take you through the steps you should follow each time you encounter
an error:

1) Read the error message carefully.


Every time you make a mistake, you will obtain an error message. Sometimes, this message will be
quite specific; you will be able to immediately spot the mistake and correct it. Other times, though, it
will sound more general. Then, it will be your job to find where the error stems from.

2) If you encounter an error while you are replicating code you’ve seen in a lecture, please re-watch
that video or at least the parts about the query you are trying to execute. Remember that every
symbol and letter could make a difference! So don’t overlook the details – they might be the exact
cause of this error!

3) If the error occurs while you are trying to solve an exercise, please carefully check the files containing
the corresponding solution.

4) In some situations, however, the 3 steps described above may not help. Or… you may still have a
question, even though you’ve managed to solve the error. In that case, please search through the
existing threads in the Q&A section. If you can’t find the answer to your question, you can post a new
one there, and we’ll be happy to help.

SQL
Back to the Table of Contents

How can I speed up the process of solving the encountered problems?

While coding in MySQL, keep the following two files open, as they may contain the answers you are looking
for.

1) The SQL - Code - Lectures and Task Solutions.sql file. You can find it in the resources section of
Section 5: SQL files and use Workbench to keep this file open in a separate tab.

2) This FAQ sheet.

In both files, 1) and 2), use Ctrl + F to find a keyword related to the problem you are trying to solve quickly.

Use the FAQ sheet, the Q&A, and best of luck on your learning journey!

SQL
Back to the Table of Contents

How can I uninstall MySQL (Server + Workbench)?

Keywords: uninstall, MySQL, Server, Workbench, Windows

Q&A thread for reference:

https://learn.365datascience.com/question/how-can-i-uninstall-mysql-server-workbench/

To remove MySQL Workbench and Server from your Windows computer, you need to go through the
following 4 steps (with no exception). Make sure you complete all of them to finish the operation
successfully:

1) Uninstall MySQL from Control Panel/Programs and Features

2) Uninstall MySQL from the start menu/Firewall/Allow an App through Windows Firewall (if found there)

3) Remove all files from drive C:/ProgramData/MySQL (if this folder is hidden on your computer, you could
search for %programdata% in the start menu)

4) Remove all files from the Windows registry. To complete this step, you need to search for regedit in the
start menu. Then, remove all files from the MySQL folder in the regedit editor.

You must complete all steps from 1) to 4) before you can restart your computer and retry installing the MySQL
Workbench and Server again.

SQL
Back to the Table of Contents

SQL
Back to the Table of Contents

How can I recover the root password/RESET the password/ create a new password?

Keywords: password, recover, reset, create, new

Q&A thread for reference:

https://learn.365datascience.com/question/how-can-i-recover-the-root-password-reset-the-password-
create-a-new-password/

For Windows users:

There’s one extremely important thing to remember during the installation process, and it is the password
you are going to set!

Although it is possible to change it later, it might not be the easiest thing to do. In such occasions,
reinstallation of the software could sometimes be the quickest option.

Basically, if you need to reset your password, it’s best to read through Section B.4.3.2.1 from the following
link:

https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

There, you will find a seven-step process provided by the creators of the software, so it is as good as it can
be.

Remember that if you find it too complicated or there's something that doesn't work as indicated in the
steps, you could uninstall MySQL completely, and install it again, this time remembering your password.

If it comes down to the point of uninstalling MySQL on Windows, here is a link that describes the 4 steps you
should go through to do that (i.e. to remove the program from your computer completely).

Uninstalling MySQL (Server + Workbench)

For Mac users:

Execute the following commands:

1) sudo /usr/local/mysql/support-files/mysql.server stop to stop the server if it is running.

SQL
Back to the Table of Contents

2) sudo mysqld_safe --skip-grant-tables to start the server in safe mode.

Then, open a new terminal and try the following commands.

3) mysql -u root to log in without a password.

4)

FLUSH PRIVILEGES;

ALTER USER 'root'@'localhost' IDENTIFIED BY '<YourNewPass>'; to update the user’s password

and

5) sudo /usr/local/mysql/support-files/mysql.server start to start the server.

SQL
Back to the Table of Contents

Installation stops at “Starting Server” Configuration Step. What can I do?

Keywords: install, configuration step, ‘starting server’

Q&A thread for reference:

https://learn.365datascience.com/question/installation-stops-at-starting-server-configuration-step-what-
can-i-do/

Failure to execute configuration steps during installation may result from the following problems:

1) Incompatibility between your Windows Operating System and the version of Workbench you have
installed (for instance, if your computer is X86 but you are trying to install X64, you may encounter such
issues).

2) Failing to properly clean the MySQL files from the registry of your computer after an unsuccessful attempt
to install Workbench. Please refer to the following explanation of this problem.

Uninstalling MySQL (Server + Workbench)

SQL
Back to the Table of Contents

Configuration stops at “Initializing Database”. How can I fix this?

Keywords: install, configuration, initializing database

Q&A thread for reference:

https://learn.365datascience.com/question/configuration-stops-at-initializing-database-how-can-i-fix-this/

Please open the my.ini configuration file that should be found in the following folder:
"C:\ProgramData\MySQL\MySQL Server <version>\my.ini"
Then, open the file and at the end, add the phrase lower_case_table_names=1 (or, if it is already there but
it equals a different value, set it up to equal 1).
Finally, save the file and try installing MySQL again.

SQL
Back to the Table of Contents

How can I Download MySQL Server and Workbench on a Mac?

Keywords: install, Mac, macOS, MySQL, Server, Workbench

Q&A thread for reference:

https://learn.365datascience.com/question/how-can-i-download-mysql-server-and-workbench-on-a-mac/

Lecture for reference:

https://learn.365datascience.com/courses/sql/installing-mysql-on-macos-and-unix-systems/

Basically, the installation of MySQL Workbench on a Mac differs from the installation process on Windows.
In case the instructions we’ve provided so far haven’t been helpful, here’s an alternative solution which
involves no actual installer. You just need to download two DMG Archive files, and then use them to install
the program.
From this link, https://dev.mysql.com/downloads/mysql/,
you need to download a Community Server that is for the Mac OS X operating system.

Then, from this link, https://dev.mysql.com/downloads/workbench/,


download the only DMG Archive file available.

SQL
Back to the Table of Contents

After you have installed them, open the first DMG Archive and follow the instructions.
Please remember any passwords you create or see on the way, as you will need them when starting the
MySQL server.

SQL
Back to the Table of Contents

ROLLBACK doesn’t work. How can I solve this problem?

Keywords: ROLLBACK

Q&A thread for reference:

https://learn.365datascience.com/question/rollback-doesn-t-work-how-can-i-solve-this-problem/

Lecture for reference:

https://learn.365datascience.com/courses/sql/the-update-statement-part-i/

There are very few reasons that could lead to this problem. We believe there is a setting that, for some
reason, has been switched on or off, and that’s what causes the issue here.
In the SQL editor of MySQL Workbench, there is the possibility to toggle the autocommit mode by pressing a
single button. This is the third of the three icons seen in the red rectangle. If you’ve pressed this button, it
means that this mode will be turned on, and each statement will be committed immediately.

Please check if it has been left intact and you can see the three icons within the red rectangle in color, just as
it is shown in the picture above.

(When the button has been pressed, the autocommit mode will be toggled on, and the tick and the X button
will probably appear grey.

If this is the case, please toggle off the autocommit button by pressing the third of the icons to see the tick
and the X button in blue again.)

SQL
Back to the Table of Contents

Why do I get Error Code: 1452: Cannot Add or Update Child Row: INSERT record 999903?

Keywords: Error Code: 1452, update, child row, insert

Q&A thread for reference:

https://learn.365datascience.com/question/why-do-i-get-error-code-1452/

Lecture for reference:

https://learn.365datascience.com/courses/sql/the-insert-statement-part-ii/#assignment

Please stick to our general request to execute all code you see in the lectures and the exercises, in the given
order. Doing this will prevent you from encountering some errors, such as this one – Error Code: 1452.

REASON FOR THE ERROR:

This error appears if you have already created another table, employees, where you have missed inserting
data about the individual with id 999903. The relationship you have established
between employees and dept_emp requires that you first insert a record in employees, and then insert a
(related) record in dept_emp.

ON DELETE CASCADE means that if you remove record 999903 from employees, record 999903 will
automatically be removed from dept_emp as well.
In brief, make sure the relationship between employees and dept_emp is valid and 999903 exists in
employees so that you don’t get the same error the next time you try inserting 999903 in dept_emp.

SOLUTION:

As explained in the article preceding this video, double-check if you’ve first inserted information about
employee number 999903 in the employees table. Only then you should proceed with inserting information
in the titles and dept_emp tables.

SQL
Back to the Table of Contents

What does the minus sign ( – ) mean in ORDER BY –a.emp_no DESC;

Keywords: ORDER BY, minus sign, -

Q&A thread for reference:

https://learn.365datascience.com/question/what-does-the-minus-sign-mean-in-order-by-a-emp-no-desc/

Lecture for reference:

https://learn.365datascience.com/courses/sql/union-vs-union-all/#assignment

1) ORDER BY a.emp_no DESC;

If you end the relevant query this way, you will obtain an output ordered with the highest employee number
on top, the lowest employee number down the list, and the null values at the end.

the top part of the output has been displayed

2) ORDER BY a.emp_no ASC;

This ending of the query will do the opposite - the null values will be on top, and then the employee numbers
will grow from the lowest to the highest.

SQL
Back to the Table of Contents

the top part of the output has been displayed

For options 3) and 4), remember that using ORDER BY followed by a minus sign works for numeric data only!
3) ORDER BY -a.emp_no DESC;

Using this code, you will first order the employees from the lowest to the highest number, and then leave
the null values at the end.

the top part of the output has been displayed

4) ORDER BY -a.emp_no ASC;

Following the logic explained so far, this ending would list the null value first, and will then order all
employees from the highest to the lowest number.

SQL
Back to the Table of Contents

the top part of the output has been displayed

Depending on the situation, you may choose between 1), 2), 3), and 4). We think 3) suits our example best.
That's why we have ended the query with ORDER BY -a.emp_no DESC; .

Why would using a minus sign in such a situation be useful at all?


Specifically, the combination used in 3) is a frequently used technique because it allows the user to sort their
output in ascending order, without starting with a (sometimes large) number of null values. In other words,
if the user prefers to see the null values at the end of the output, using ORDER BY -a.emp_no DESC; is a very
convenient choice.
Why does it work that way?
This is simply a peculiarity of the SQL syntax, and we must always comply with it.

SQL

You might also like